阻止向上冒泡stopPropagation(),另一种写法

之前看的都是直接给元素添加click事件,然后在click事件里面写。如下:

$("span").click(function(event){
     
	event.stopPropagation();
	alert("The span element was clicked.");
});

但是如果想要用οnclick=xxx()来调用点击事件时,直接写

event.stopPropagation(); 

会报错:Typeerror:Cannot read property ‘stopPropagation’ of undefined

正确写法是:

function updateCatalog(){
     
	//阻止向上冒泡
    window.event.stopPropagation();
});

你可能感兴趣的:(stopProgagation,js,event)