gpt4 book ai didi

jquery - 我是否正确理解 jQuery 委托(delegate)函数?

转载 作者:行者123 更新时间:2023-12-01 02:45:23 25 4
gpt4 key购买 nike

我知道 div 将出现在我的页面 future DOM 中的某个时刻,并且我知道它的 id(它由 SharePoint javascript 生成) - 我可以使用 jQuery delegate在该 div 存在于 DOM 中之前将事件处理程序附加到该 div 上?

此外,对于这个特定场景,这与 .live() 相比如何?

最佳答案

简短回答:

长答案:从 jQuery 1.7+ 开始 .on()在您提到的两个之前首选,它们已被弃用。这是 .on() 上的示例:

    $('#parent').on("click", "span.children", function() {
if ( confirm("Are you sure?") ) {
console.log(this);
}
});

关于jquery - 我是否正确理解 jQuery 委托(delegate)函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12069806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com