0
我想停止我的事件sayHello1如何在JS中停止事件?
var sayHello1 = function(e) {
console.log("hello1");
e.stopMe = true;
e.preventDefault(); // doesn't work
e.stopPropagation(); // doesn't work
return false; // doesn't work
};
var sayHello2 = function(e) {
console.log("hello2"); // Still fired !
if (e.stopMe) console.log("stop hello2"); // works
};
document.addEventListener("click", sayHello1);
document.addEventListener("click", sayHello2);
後
「e.stopMe」不能幫助制止sayHello2,但沒有辦法做到這一點! (想象一下firefox & Co在他們的瀏覽器上使用名稱「stopMe」!)
'e.stopImmediatePropagation()' – zerkms
與它自己的outerHTML取代元素...然後添加新的監聽器。老聽衆將會消失 – charlietfl