如何在選中或取消選中複選框後啓用和禁用一個div內的下一個輸入?
我正在嘗試使用jQuery nextAll,但如果div涉及元素,則不起作用。我的HTML:禁用並啓用div內的下一個輸入字段
<input class='box' type='checkbox'/>Option -
<div class='box-2' style='display: inline-block'>
Quantity <input type='number' disabled/>
</div>
<input class='box' type='checkbox'/>Option 2 -
<div class='box-2' style='display: inline-block'>
Quantity <input type='number' disabled/>
</div>
實際上,我用下面的jQuery的嘗試:
$(document).ready(function()
{
$('.box').change(function()
{
var set = $(this).is(':checked') ? false : true;
$(this).nextAll('div.box-2 input').first().attr('disabled', set);
});
});
我知道什麼是錯的,但我不能使它發揮作用。 JS Fiddle here
嘗試'.prop('disabled',true);'複選框 –