例如:
$('#enquiry-form').on('click','.close', function(){
$(this)..code..
});
$(this)
会引用 '.close'
但有没有办法引用 $('#enquiry-form')
以类似于使用 javascript 的 this
或 $(this)
?
最佳答案
您可以使用 event.delegateTarget获取委托(delegate)目标。
$('#enquiry-form').on('click','.close', function(event){
alert($(event.delegateTarget)[0].id);
});
This property is most often useful in delegated events attached by .delegate() or .on(), where the event handler is attached at an ancestor of the element being processed. It can be used, for example, to identify and remove event handlers at the delegation point, jQuery Doc.
关于javascript - 我可以使用它来引用委托(delegate)元素的选择器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22065996/