在动态建立的元素上进行事件绑定? - Event binding on dynamically created elements?

问题:

I have a bit of code where I am looping through all the select boxes on a page and binding a .hover event to them to do a bit of twiddling with their width on mouse on/off . 我有一些代码,我在其中循环浏览页面上的全部选择框,并将.hover事件绑定到它们,以便在mouse on/off对其宽度进行一些调整。 app

This happens on page ready and works just fine. 这在页面准备就绪时发生,而且工做正常。 oop

The problem I have is that any select boxes I add via Ajax or DOM after the initial loop won't have the event bound. 个人问题是,在初始循环以后,我经过Ajax或DOM添加的全部选择框都没有事件绑定。 this

I have found this plugin ( jQuery Live Query Plugin ), but before I add another 5k to my pages with a plugin, I want to see if anyone knows a way to do this, either with jQuery directly or by another option. 我已经找到了这个插件( jQuery Live Query Plugin ),可是在我使用插件向页面添加另外一个5k以前,我想看看是否有人知道直接使用jQuery或经过其余方法作到这一点的方法。 spa


解决方案:

参考一: https://stackoom.com/question/qrO/在动态建立的元素上进行事件绑定
参考二: https://oldbug.net/q/qrO/Event-binding-on-dynamically-created-elements
相关文章
相关标签/搜索