日期:2014-05-16  浏览次数:20337 次

事件执行的次序
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=utf-8 "   />
<title> asd </title>
</head>

<body>
<div   id= "box "   style= "border:1px   solid; "   onmousedown= "alert( 'b '); "> <a   href= "# "   onclick= "alert( 'xx '); "> close </a> </div>

</body>
</html>

怎样才可以点击   close只弹出xx

点击div弹出b
谢谢

------解决方案--------------------
IE6.0测试通过,ff下要设置事件浮生
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 " />
<title> asd </title>
<script type= "text/javascript ">


function getEvent()
{
if ( window.event )
return window.event;
var ff = arguments.callee;

while ( caller = ff.caller ){
ff = ff.caller;
}
return ff.arguments[0];
}

function stopEvent()
{

var evnt = getEvent();
alert(evnt);
if ( evnt.stopProgagation ){
evnt.stopProgagation();
}else{
evnt.cancelBubble = true;
}
}

function clickA(obj)
{
alert( 'xx ');
stopEvent();
}
</script>
</head>

<body>
<div id= "box " style= "border:1px solid; " onmousedown= "alert( 'b '); "> <a href= "# " onclick= "clickA(this); "> close </a> </div>

</body>
</html>