标签:style blog http io ar color os sp for
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>取消form表单提交或a打开的超连接</title> 6 <script src="/js/jquery-1.8.2.js"></script> 7 <script language="javascript" type="text/javascript"> 8 $(function () { 9 $("*").each(function (index, item) { 10 $(item).bind("click", function (event) { 11 output("事件源:" + event.target.id + "," + event.target.tagName + ",事件对象:" + event.currentTarget.id);//DOM2会产生冒泡 12 //取消form表单提交或a打开的超连接 13 event.preventDefault(); 14 //同样也支持取消事件冒泡 15 //event.stopPropagation(); 16 }); 17 }); 18 }); 19 function output(text) { 20 $("#content").append(text + "<br/>"); 21 } 22 </script> 23 </head> 24 <body id="body"> 25 <div id="parent"> 26 <div id="child"> 27 点击这里 28 <a id="link" href="http://www.baidu.com">超连接</a> 29 <form id="form" action="http://www.baidu.com"> 30 <input id="submit" type="submit" value="submit"/> 31 </form> 32 </div> 33 </div> 34 <div id="content"> 35 </div> 36 </body> 37 </html>
JQuery中event的preventDefault和stopPropagation介绍
标签:style blog http io ar color os sp for
原文地址:http://www.cnblogs.com/qiyebao/p/4162222.html