jquery - 如何阻止动态元素在 Jquery/Jquery Mobile 中重新绑定(bind)?

标签 jquery events jquery-mobile binding

我通常会阻止对一个元素的多次绑定(bind),如下所示:

$(document)
    .find('.ui-input-search input')
    .filter(function() { return $(this).jqmData('bound') !== true; })
    .jqmData('bound', true)
    .on('change keyup', function (e) {
        //do sth
    });

当元素位于页面上并且“可以使用”时效果很好。

问题是,我想对动态添加到页面的元素执行相同的操作。在这些元素上,JQM 在某些情况下不会对元素进行增强,因此绑定(bind)到正在创建的元素有时不起作用。

问题:
如果我不想在页面隐藏上取消绑定(bind),我该如何更改上述代码以在设置绑定(bind)后也锁定元素?

所以我想做这样的事情:

$(document).on('change keyup','.ui-input-search input', function (e) {
  // bind to the selector only once
});

但由于 IE,我无法使用 :not 选择器 .ui-input-search input:not(.bound),所以我很好奇:

感谢反馈!

最佳答案

but I can't use the :not selector .ui-input-search input:not(.bound) because of IE, so I'm curious:

引用the browser support page :

Regardless of a browser's support of CSS selectors, all selectors listed at api.jquery.com/category/selectors/ will return the correct set of elements when passed as an argument of the jQuery function.

在使用 jQuery 形成集合时,您可以使用 :not 选择器,无论浏览器的 CSS 引擎是否支持该选择器。

关于jquery - 如何阻止动态元素在 Jquery/Jquery Mobile 中重新绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15415338/

相关文章:

javascript - 在手机上设置超时

javascript - jQueryMobile - 滚动到一个位置 onLoad

jQuery UI CSS 导入似乎不起作用

javascript - jQuery onclick 函数不会在嵌套的 div 上触发

javascript - 基于字符串变量访问嵌套的javascript对象

.net - Avalon 文本编辑器中上下键的光标位置没有改变

objective-c - Objective-C 中的鼠标坐标?

窗口大小调整事件之前和之后的 JavaScript

jquery-ui - 触发 jQuery UI 事件 : ui-selectable

jQuery 移动控件组