我知道 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/