使用 chrome 开发工具查看节点上的侦听器给我带来了麻烦。似乎它没有在我的动态加载的内容上检测到侦听器(但不幸的是,我没有在小提琴中复制它)。但是,它不会注册由 jQuery 委托的事件。
有什么办法可以“刷新”它的“事件知识”?
var div = document.getElementsByTagName("div")[0],
p = document.getElementsByTagName("p")[0],
vanillaListen = function () {
console.log("clicked via just JS");
};
//attach pure JS listener
//shows up in Event Listeners pane
p.addEventListener("click", vanillaListen);
//attach jquery listener
$("body").on("mouseover", "div", function () {
console.log("div mouse'd over via jQuery"); //does not show up in Event Listeners pane
});
//attach listener from ajax loaded content
$(document).ready(function () {
setTimeout(function () {
$.ajax({
type: "post",
url: "/echo/html/",
dataType: "html",
data: {
html: "<p onClick=\"alert('ajax attached inline event')\">dynamic <p></p>",
delay: 1
},
success: function (returnedData) {
//inline onClick shows up in Event Listeners pane
$("body").append(returnedData);
}
});
}, 2000);
});