javascript 阻止事件元素默认行为和传播(冒泡)

document.getElementById('id').onclick = function(e){
	e = e || window.event;
	var target = e.target || e.srcElement;

	// do something

	//prevent default action
	if(typeof e.preventDefault === 'function'){
		e.preventDefault();
		e.stopPropagation();
	}else{
		e.returnValue = false;
		e.cancelBubble = true;
	}
}

你可能感兴趣的:(JavaScript)