<li>
<input type="checkbox" id="master" />
<ul>
<li>
<input type="checkbox" />
$('input').bind('change', function() {}); // exists elsewhere, cannot change
當我點擊頂層輸入,我想設置.prop('checked', true)
其所有的孩子,但我想避免觸發change
事件爲每個孩子複選框。
如何將.prop('checked', true)
設置爲輸入而不觸發change
?
編輯:(擴大)
$('#master').click(function() {
$(this).parent().find('input').each(function(n, in) {
$(in).prop('checked', true); // this triggers a change event that I need to stop
});
});
我想重現我的症狀,你必須使用一個上層複選框,檢查所有的較低水平,而不是箱子一個單獨的按鈕 – tester 2012-02-03 21:58:17
還沒問題http://jsfiddle.net/8JsP4的/ 1 /也許你可以在我的小提琴中重現這個問題? – 2012-02-03 22:00:21
掛上,只是看着你的編輯,你的代碼不會做任何事情。 '$(this).find(...'將不會返回任何內容,因爲'this'是一個不包含**任何內容的輸入。你的html與你發佈的內容實際上是不同的嗎? – 2012-02-03 22:02:36