当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JQuery事件e参数的方法preventDefault()取消默认行为

JQuery事件e参数的方法preventDefault()取消默认行为

2018年12月09日  | 移动技术网IT编程  | 我要评论

jquery事件的e参数的方法preventdefault()可以取消对象的默认行为。如下代码:

. 代码如下:


<!doctype html>
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title></title>
<script src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("a").click(function (e) {
alert($(this).text());
e.preventdefault();//取消默认行为,没有这句话的话,会跳转到baidu网站上
});
});
</script>
</head>
<body>
<a href="https://www.baidu.com">baidu</a>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网