绑定禁用后禁用的输入仍然响应鼠标事件
我使用 Khavilo Dmitry 的 jQuery 复选框代码 作为复选框和单选按钮。这看起来不错,但他的禁用代码不起作用。正如预期的那样,该按钮呈灰色,但它仍然响应鼠标单击。
我猜测问题在于他绑定禁用如下:
var ch = this; /* Reference to DOM Element*/
...
$ch.bind('disable', function() {ch.wrapperInner.addClass(settings.cls+'-disabled');})
.bind('enable', function() {ch.wrapperInner.removeClass(settings.cls+'-disabled');});
此代码是否删除了任何会禁用鼠标事件的默认绑定?谢谢。
I'm using Khavilo Dmitry's jQuery checkbox code for checkboxes and radio buttons. This looks good, but his disable code doesn't work. The button is grayed out, as expected, but it still responds to mouse clicks.
I'm guessing that the problem is that he binds to disable as follows:
var ch = this; /* Reference to DOM Element*/
...
$ch.bind('disable', function() {ch.wrapperInner.addClass(settings.cls+'-disabled');})
.bind('enable', function() {ch.wrapperInner.removeClass(settings.cls+'-disabled');});
Is this code removing any default binding that would disable mouse events? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
代码所做的唯一事情是将函数绑定到事件“disable”和“disable”。 'enable'
当'disable'事件被触发时,他正在向内部跨度添加一个类
jquery-checkbox-disabled
。他在启用事件中将其删除。正如您所看到的,该复选框确实被禁用,但为您提供自定义外观的元素只是仍然可单击的常规跨度。
看起来 Dmitry 正在将这些跨度的单击事件传递给隐藏的复选框。
这就是为什么即使复选框被禁用,您仍然可以获得该复选框的点击事件。正在以编程方式单击该复选框。
因此,如果您的问题是尝试检测复选框何时更改,那么我建议您使用更改事件,因为它似乎没有遇到相同的问题。
http://jsfiddle.net/vW6gj/
The only thing that code is doing is binding functions to the events 'disable' & 'enable'
When the 'disable' event is fired he is adding a class
jquery-checkbox-disabled
to the inner span. He removes it on the enable event.As you can see, The checkbox does get disabled, but the elements that provide you that custom look are just regular spans which are still clickable.
It appears that Dmitry is passing on the click events of these spans to the hidden checkbox.
This is why you're still getting the click events of the checkbox even though it is disabled. The checkbox is being programatically clicked.
So if your issue is that you're trying to detect when the checkbox has changed, then I recommend you use the change event as it does not seem to suffer from the same issue.
http://jsfiddle.net/vW6gj/