Last active
August 29, 2015 14:04
-
-
Save hehongwei44/5fb2134a70ab8379849e to your computer and use it in GitHub Desktop.
阻止事件冒泡和默认行为的通用函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 阻止事件冒泡的通用函数 | |
* */ | |
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