Skip to content

Instantly share code, notes, and snippets.

@hehongwei44
Last active August 29, 2015 14:04
Show Gist options
  • Save hehongwei44/5fb2134a70ab8379849e to your computer and use it in GitHub Desktop.
Save hehongwei44/5fb2134a70ab8379849e to your computer and use it in GitHub Desktop.
阻止事件冒泡和默认行为的通用函数
/**
* 阻止事件冒泡的通用函数
* */
function stopBubble(e) {
if (e && e.stopPropagation) {
e.stopPropagation();
} else {
window.event.cancelBubble = true;
}
}
/**
* 防止发生默认浏览器行为的通用函数
* */
function stopDefault(e) {
if (e && e.preventDefault) {
e.preventDefault();
} else {
window.event.returnValue = false;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment