gpt4 book ai didi

jquery - 设置 $.prop() 而不触发更改

转载 作者:行者123 更新时间:2023-12-03 22:24:32 24 4
gpt4 key购买 nike

<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
});
});

最佳答案

您所描述的是默认功能。从 javascript 更改元素不会触发更改事件。

http://jsfiddle.net/8JsP4/

请注意,如果单击示例中的复选框,您会收到警报,但如果单击按钮,则不会收到警报。

关于jquery - 设置 $.prop() 而不触发更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9136000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com