如果你有这样的东西:
jQuery(selector).focus(function(){...});
jQuery(selector).focus(function(){...});
Run Code Online (Sandbox Code Playgroud)
焦点会触发两次,无论如何我可以纠正/防止这种情况吗?
使用data('events')查找事件处理程序:
var isBound = function(el, ev) {
var found = false;
$.each($(el).data("events"), function(i, e) {
if (i === ev) {
found = true;
}
});
return found;
}
if (!isBound(selector, 'focus')) {
$(selector).bind('focus', fn);
}
Run Code Online (Sandbox Code Playgroud)
我想你也可以.one()在jQuery中使用这个函数,看看http://api.jquery.com/one/
| 归档时间: |
|
| 查看次数: |
6609 次 |
| 最近记录: |