码迷,mamicode.com
首页 > 其他好文 > 详细

取消事件的默认动作

时间:2016-01-06 23:14:56      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

•(window.event.returnValue)returnValue属性,如果将returnValue设置为false,就会取消默认事件的处理。在超链接的onclick里面禁止访问href的页面。
在表单校验的时候禁止提交表单到服务器,防止错误数据提交给服务器、防止页面刷新。(onsubmit="window.event.returnValue=false;")
•window.event.returnValue不兼容火狐浏览器
•FireFox:e. preventDefault();取消事件的默认动作。

直接写return false;IE、FF、Chrome都可以

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
//页面加载的时候
onload = function () {
//给单机a标签增加一个点击事件
document.getElementById(‘a1‘).onclick = function (evt) {
//当单机的时候有alt的时候
if (arguments[0].altKey) {
//弹出当前事件
alert(new Date().toLocaleTimeString());

//IE中取消默认事件的方法,好像现在也不行了
//window.event.returnValue = false;

//火狐中取消默认事件的方法。
arguments[0].preventDefault();

//支持火狐和IE。据说 推荐使用的方法
//return false;
};
};
};
</script>
</head>
<body>
<a href="http://www.baidu.com" id="a1" target="_blank">跳到百度去,加alt可以显示时间</a>
</body>
</html>

取消事件的默认动作

标签:

原文地址:http://www.cnblogs.com/clcloveHuahua/p/5107724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!