如何检查单选按钮是否已经与“更改”绑定事件处理程序
如果我有单选按钮:
<input id="y0" type="radio" name="myRadioBtns" value="a" checked> <label for="y0"></label>
<input id="y1" type="radio" name="myRadioBtns" value="b"> <label for="y1"></label>
<input id="y2" type="radio" name="myRadioBtns" value="c"> <label for="y2"></label>
单选按钮可能已经绑定了更改事件处理程序,如下所示:
$('input[name='myRadioBtns']').change(function() {
//EVENT HANDLER
});
我需要检查单选按钮是否已经绑定了“更改”事件处理程序。
我的问题是如何检查单选按钮是否已经与“更改”事件处理程序绑定?
If I have radio buttons :
<input id="y0" type="radio" name="myRadioBtns" value="a" checked> <label for="y0"></label>
<input id="y1" type="radio" name="myRadioBtns" value="b"> <label for="y1"></label>
<input id="y2" type="radio" name="myRadioBtns" value="c"> <label for="y2"></label>
The radio buttons may have already bound a change event handler like following:
$('input[name='myRadioBtns']').change(function() {
//EVENT HANDLER
});
I need to check if the radio buttons have already bound with a "change" event handler or not.
My question is How to check if the radio buttons has already bound with a "change" event handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在绑定另一个更改事件之前测试是否已绑定更改事件,请使用以下命令:
If you want to test whether a change event has already been bound before you bind another one, use this:
您可以通过以下方式获取绑定事件:
You can get bound events with:
此外,您还可以绑定多个命名空间更改事件,每个事件执行不同的操作。例如,如果您正在编写一个 jQuery 插件,需要将事件绑定到元素,但不删除页面上可能已设置的任何现有事件。
每当我编写 jQuery 插件时,我都会确保所有事件都像这样绑定:
Also, you can bind multiple namespaced change events that each do different things. For example if you were writing a jQuery plugin that needs to bind events to elements, but not remove any existing events that might already be set on the page.
Whenever I'm writing a jQuery plugin I make sure all events are bound like this: