<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> mm </title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>
</head>
<body>
<script type="text/javascript">
function mouseDown(event)
{
var event=event||window.event;
var loc="X="+event.screenX+"Y="+event.screenY;
var thesrc=event.target||event.srcElement;
alert(loc+" "+thesrc);
stop(event);
}
function second(event)
{
var event=event||window.event;
stop(event);
alert("this is the second");
}
document.onmousedown=function(event){
var event=event||window.event;
alert(event.type);
}
function set()
{
document.getElementById("first").onmousedown=mouseDown;
document.getElementById("second").onmousedown=second;
}
function stop(event)
{
if(event.stopPropagation)
{
event.stopPropagation();
}
else
{
event.cancelBubble=true;
}
}
function state()
{
alert(this.status);
}
window.onload=set;
</script>
<div id="first" style="padding:20px;background-color:red;width:150px;">
<div id="second" style="background-color:green;height:100px;width:100px;">
</div></div>
</body>
</html>
用兼容的方法组织了事件的向下级联或者冒泡
同时自己也有个疑问,不知是RP的问题,总是在测试发现没有写stop方法之前在IE和FF中表现是一样的,不知何故
浙公网安备 33010602011771号