2017-02-13 7 views
1

jqueryを使用してラジオボタンをクリックすると、テキストボックスを有効にできます。しかし、私はラジオボタンが変更された場合、それらを無効にする方法については得られません。jqueryでテキストボックスを無効にできません

JSFiddle http://jsfiddle.net/2LCnC/

HTML

<table> 
    <tr class="jsRadioMasterSlaveContainer"> 
    <td> 
     <input type="radio" name="radioMultiSelectCheckbox" class="jsRadioMaster" value=""> Upto N random selection count 
    </td> 
    <td style="padding: 3px;"> 
     <input type="text" placeholder="Count" id="" style="width:80px" class="jsRadioSlave" disabled/> 
    </td> 
    </tr> 
    <tr class="jsRadioMasterSlaveContainer"> 
    <td> 
     <input type="radio" name="radioMultiSelectCheckbox" id="" value="" class="jsRadioMaster"> Fixed selection count 
    </td> 
    <td style="padding: 3px;"> 
     <input type="text" name="" placeholder="Count" id="" style="width:80px" class="jsRadioSlave" disabled/> 
    </td> 
    </tr> 
    <tr class="jsRadioMasterSlaveContainer"> 
    <td> 
     <input type="radio" name="radioMultiSelectCheckbox" id="" class="jsRadioMaster"> Fixed index selection count 
    </td> 
    <td style="padding: 3px;"> 
     <input type="text" placeholder="Count" id="" style="width:80px" class="jsRadioSlave" disabled/> 
    </td> 
    </tr> 
</table> 

jQueryの

$(".jsRadioMaster").each(function() { 
    $(this).click(function() { 
    HandleMasterRadioChange($(this)); 
    }); 
}); 
function HandleMasterRadioChange(masterRadio) { 
     $(masterRadio).closest(".jsRadioMasterSlaveContainer").find(".jsRadioSlave").each(function() { 
     $(this).attr("disabled", !$(masterRadio).is(':checked')); 
     }); 
    } 

答えて

1

あなたはprop(propertyName, function)を使用して返すことができboolen同じ行にラジオに基づいて

$(".jsRadioMaster").change(function() { 
    $('.jsRadioSlave').prop('disabled',function(){ 
     return !$(this).closest('tr').find('.jsRadioMaster').prop('checked') 
    }) 
}); 

DEMO

関連する問題