gpt4 book ai didi

javascript - JQuery 更改事件循环

转载 作者:行者123 更新时间:2023-11-30 18:50:48 25 4
gpt4 key购买 nike

我有几个复选框。如果用户选中其中任何一个,我必须查看他们是否被允许这样做,如果不允许,通知他们并取消选中它。然而,这让我陷入了循环,因为它再次触发了变化!我怎么能克服这个?

$('#step_1, #step_2, #step_3, #step_4').change(function(event) {
if(!$('#section_2_active').attr('checked')){
alert('You can not select output options when "Create Output" has not been selected.');

$(this).attr('checked', false);

$('#other_stages :checkbox:not(#section_2_active, #co_t)').change();
}

});

我无法解除绑定(bind)然后重新绑定(bind)更改事件,因为有另一个插件依赖于此事件。

我还有哪些其他选择?我可以为每个复选框附加一个函数调用,但我希望有一些更优雅的东西,如果没有,我会默认为这个。

感谢大家的帮助

最佳答案

您可以使用 .trigger()要将附加参数传递给您的处理程序,我们将使用 loop。如果为 false,则不要再次运行其他元素触发器,如下所示:

$('#step_1, #step_2, #step_3, #step_4').change(function(event, loop) {
if(!$('#section_2_active').attr('checked')){
alert('You can not select output options when "Create Output" has not been selected.');
$(this).attr('checked', false);
if(loop !== false)
$('#other_stages :checkbox:not(#section_2_active, #co_t)').trigger('change', false);
}
});

关于javascript - JQuery 更改事件循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3969443/

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