JQuery事件的e参数的方法preventDefault()可以取消对象的默认行为,下有个不错的示例,大家可以参考下,希望对大家有所帮助
JQuery事件的e参数的方法preventDefault()可以取消对象的默认行为。如下代码: 
复制代码 代码如下:
 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<title></title> 
<script src="https://www.jb51.net/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> 
您可能感兴趣的文章:
