[英]jQuery trigger change on class?
I have a list of checkboxes.我有一个复选框列表。 Each checkbox has .change(function(){alert('xyz')})
.每个复选框都有.change(function(){alert('xyz')})
。 Each checkbox has a class abc
.每个复选框都有一个类abc
。
I also have an additional checkbox called 'ALL'.我还有一个名为“ALL”的附加复选框。 When the 'ALL' checkbox is changed, it changes the state of all the other checkboxes.当“ALL”复选框更改时,它会更改所有其他复选框的状态。
I would like the change of the 'ALL' checkbox to trigger the change ( .change(...)
) of all the other checkboxes.我希望更改“ALL”复选框以触发所有其他复选框的更改( .change(...)
)。 But since the state of the other checkboxes is done programmatically, it doesn't work by itself.但是由于其他复选框的状态是以编程方式完成的,因此它本身并不能正常工作。
I've tried to use $('.abc').change()
to trigger the change event of all the checkboxes, but it didn't work.我尝试使用$('.abc').change()
来触发所有复选框的更改事件,但是没有用。
What am I doing wrong, and how can the task at hand be achieved ?我做错了什么,如何完成手头的任务?
BTW, if I do $('#id_of_a_specific_checkbox').change()
it works great.顺便说一句,如果我这样做$('#id_of_a_specific_checkbox').change()
效果很好。
Thank you.谢谢你。
UPDATE更新
Example of what I have: http://jsfiddle.net/ZqJvc/我所拥有的示例: http : //jsfiddle.net/ZqJvc/
It's pretty much what I have in the large project... And in the short example it works :/这几乎是我在大型项目中所拥有的......在简短的例子中它有效:/
But in the real project it doesn't work.但在实际项目中它不起作用。 The only difference is that in the real project I have lots of checkboxes.唯一的区别是在实际项目中我有很多复选框。 Weird... I guess it's back to the debugger.奇怪......我想它回到了调试器。 Thanks.谢谢。
UPDATE更新
After Chrome crashed completely... I restarted the browser and it just worked as in the example above. Chrome 完全崩溃后……我重新启动了浏览器,它就像上面的例子一样工作。 Sorry wasting our time.抱歉浪费了我们的时间。 Thanks again, guys.再次感谢各位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.