preventDefault()阻止浏览器默认行为

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function stopDefualt(e){
if(e&&e.preventDefault){
e.preventDefault();//如果是FF下执行
}else{
window.event.returnValue=false;///如果是IE下执行
}
return false;
}
window.onload=function(){
var test = document.getElementById("test");
test.onclick=function(e){
alert("不跳转");
stopDefualt(e);
}
}
</script>
</head>
<body>
<a href="http://www.baidu.com" id="test" >不能跳转</a>
</body>
</html>

posted @ 2012-05-10 17:49  weblift  阅读(339)  评论(0编辑  收藏  举报