Jquery.live() 观察在 DOM 中加载新元素
当元素在 DOM 中创建时是否可以观察到“load”事件?更具体地说,我有兴趣观察是否添加了新的选择框,然后对选择框中的选项进行排序。
我尝试过类似的方法:
$("select").live("load", mySortSelectFunction)
这显然行不通。也许“load”事件不会在选择元素上触发?
如果没有“load”事件,那么当 DOM 中的选择框准备就绪时如何才能收到通知呢?我想避免在创建选择框的任何地方从代码中触发一些自定义事件。我想在全局脚本中添加一个小事件监听器,然后所有选择框都会自动排序,无论它们何时创建。
亲切的问候,
克里斯蒂安·索恩·詹森
Is it possible to observe the the "load"event when elements have been created in the DOM? More specific, I'm interested in observing if new select boxes have been added, and then sort the options in the selectbox.
I've tried stuff like:
$("select").live("load", mySortSelectFunction)
This apparently does not work. Maybe the "load" event doesn't fire on the select element?
If there is no "load" event, then how would it be possible to get a notification when a select box is ready in the DOM? I want to avoid firing some custom event from code everywhere the selectboxes are created. I want to just add one little eventlistener in a global script, and then all selectboxes are automatically sorted no matter when they are created.
Kind regards,
Christian Sonne Jensen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试 jquery liveQuery - 它完全可以满足您的要求。
Try jquery liveQuery - it does exactly what you want to do.
没有您可以实现的此类事件或功能。您基本上可以尝试在页面加载时查找所有选择元素,然后应用排序功能
There is not such event or functionality that you can achieve. You can basically try to find all select elements on page load and then apply the sorting function