阻止标签的默认行为发生
2017-03-06 16:34
183 查看
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JS阻止链接跳转</title> <script type="text/javascript"> function stopDefault( e ) { if ( e && e.preventDefault ) e.preventDefault(); else window.event.returnValue = false; return false; } </script> </head> <body> <a href="http://www.baidu.com" id="testLink">百度</a> <script type="text/javascript"> var test = document.getElementById('testLink'); test.onclick = function(e) { alert('我的链接地址是:' + this.href + ', 但是我不会跳转。'); stopDefault(e); } </script> </body> </html>
preventDefault方法就是可以阻止它的默认行为的发生而发生其他的事情
stopPropagation()是用来阻止事件冒泡
相关文章推荐
- 阻止浏览器发生默认行为
- js阻止事件冒泡和标签默认行为
- 阻止a标签默认行为的几种简单方法
- 阻止a标签默认行为的几种简单方法
- js阻止事件冒泡和标签默认行为
- 【转】阻止浏览器发生默认行为
- 阻止a标签默认行为的几种简单方法
- Javascript可以兼容各浏览器的阻止默认行为发生的方法
- 让A超链接无效的办法 阻止元素发生默认的行为
- js 阻止元素发生默认的行为ie兼容
- 阻止a标签默认行为的几种简单方法
- 阻止a标签跳转的默认行为
- 怎么样阻止a标签的默认行为
- Angular ngClick 阻止冒泡和默认行为
- jQuery 中的事件冒泡和阻止默认行为
- javascript 阻止事件冒泡 与 浏览器的默认行为
- jQuery 中的事件冒泡和阻止默认行为
- js阻止冒泡和默认事件(默认行为)详解
- Study JavaScript《停止冒泡和阻止浏览器默认行为》
- 阻止浏览器冒泡和默认行为