JQuery事件之取消默认行为 【转】
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="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="http://www.baidu.com">baidu</a> </body> </html>
相关推荐
84483065 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
tztzyzyz 2020-07-05
delmarks 2020-06-28
89510194 2020-06-27
牵手白首 2020-06-14
tztzyzyz 2020-05-31
81463166 2020-05-17
88570299 2020-05-17
delmarks 2020-05-17
donghongbz 2020-05-15
tztzyzyz 2020-05-15
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%&qu
牵手白首 2020-05-14
Chriswang 2020-04-30
83510998 2020-05-03