这是我的dom中项目列表的一些事件处理。
使用事件委托,单击处理程序位于父容器上
$( "#list" ).on( "click", "a", (event) => {
event.preventDefault();
event.stopImmediatePropagation();
let text = $(this).parent().children().last().text();
// The following HAS content (seen in the dev tools debugger !!!!)
// $(this).parent().children().last().text()
// But the text variable gets No content - WHY ?
// "" is printed....
console.log(text);
});
有任何想法吗?任何帮助表示赞赏。
因为您使用箭头功能,并且this
箭头功能window
在浏览器中。
$( "#list" ).on( "click", "a", function (event) {
event.preventDefault();
event.stopImmediatePropagation();
let text = $(this).parent().children().last().text();
debugger
console.log(text);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句