我通常会阻止对一个元素的多次绑定(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:
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/