0

ラジオ2で有効になっている場合、テキストボックスBのフォーム送信中に入力を検証したいのですが、テキストボックスBの入力検証が以下のコードで機能していません。

<script type="text/javascript">
$(document).ready(function() 
{
    $("#form").validate(
    {
        rules: {B: "required",}
    }); 

   ​$(':radio').change(function() 
   {
        $('#B').prop('disabled', !(this.value == '2' && this.checked));
   })​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​;         
});
</script>

<form id="form" name="form" method="post" action="">
<table><tr>
<td width><input type="radio" name="A" id="1" value="1" />1</td>
<td width><input type="radio" name="A" id="2" value="2" />2</td>
</tr></table>
<input name="B" type="text" id="B" disabled="disabled"/>
<input type="submit" name="form" id="Submit" value="Submit" />
</form>
4

1 に答える 1

1

これを試して、

$(document).ready(function() 
{
    $("#form").validate({
            rules: {
                B: "required",
            }
        });
    $('input:radio[name="A"]').change(
    function(){
        if ($(this).is(':checked') && $(this).val() == '2') {
            $('#B').removeAttr('disabled');
        }else if($(this).is(':checked') && $(this).val() == '1'){
            $('#B').attr('disabled', 'disabled');
        }
    });
});
于 2012-12-12T03:35:50.313 に答える