<html>
<head>
<title>Javascript Event Phases</title>
</head>
<body>
<form id="frm" onclick="frmClick()" >
<input type="button" id="btn" value="Button" onclick="btnClick(event)" />
</form>
</body>
</html>
<script>
document.onclick = function()
{
window.alert("Document clicked!");
};
function btnClick(e)
{
if (window.event) {
window.event.cancelBubble = true;
}
else {
e.stopPropagation();
}
window.alert("Button clicked!");
}
function frmClick()
{
window.alert("Form clicked!");
}</script>
以上代码来自:http ://triaslama.wordpress.com/2008/07/03/javascript-event-phases-capturing-and-bubbling/
问题:
if (window.event) {}
,这条线只适用于IE吗?为什么我们可以用这条线来检测IE?e.stopPropagation();
这条线是否适用于除 IE 之外的其他浏览器(firefox、safari ...)?