2
A
回答
7
您可以使用.on()将事件绑定到尚不存在的元素。但除此之外,我认为你没有太多的解决方案。
你想要做什么?
$(document).on("click", "#futureID", function(){
/* whenever <a id='futureID'>Hello</a> is created,
it will have this functionality */
});
/* Sometime in the future, you add the link */
$("body").append("<a href='index.php' id='futureID'>Hello</a>");
该链接将具有上述功能已连接。
1
从版本1.3开始,您可以使用jQuery's "Live" functionality。
1
如果您将它们添加到代码中,则可以使用.live()方法(阅读文档)。
例如,如果通过Web服务调用将它们添加到DOM,则可以使用事件委派。我会留给你看看!如果你正在向DOM添加一堆元素,那么事件委托就是要走的路。
相关问题
- 1. jquery选择不存在的元素
- 2. 如何选择尚不存在的元素(jQuery)并更改其样式?
- 3. jQuery选择 - 不选择内部元素
- 4. JQuery .eq选择器不选择元素
- 5. 选择不存在的元素?
- 6. 如何通过jQuery中尚不存在的元素的事件生成元素()
- 7. JQuery - 元素选择
- 8. 在jQuery中选择元素
- 9. 在jQuery中选择元素
- 10. jQuery的 - 如何设置一个选择不存在尚未
- 11. 在不同深度选择元素,jquery
- 12. jQuery的 - 从元素中选择元素
- 13. 选择值选择元素witht jQuery的
- 14. 选择元素的jQuery
- 15. jQuery的元素选择
- 16. jQuery的选择元素xpath
- 17. '选择'元素的jQuery ui.datepicker
- 18. 的jQuery选择元素
- 19. 选择元素+ jQuery的
- 20. jQuery的元素选择
- 21. 的jQuery选择了元素
- 22. jQuery的HTML元素选择
- 23. JQuery基础知识 - 选择缓存元素中的元素
- 24. jQuery获取搜索选择器,如果元素不存在
- 25. jquery选择只是选择元素,而不是它的选项
- 26. jquery选择li元素
- 27. jquery选择子元素
- 28. 用jQuery选择新元素
- 29. jQuery选择多个元素
- 30. jQuery选择。查找元素
根据您的HTML结构,您可以使用事件委托。 – SolutionYogi 2009-07-13 21:27:22