We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在事件里头取消事件的默认动作。 例如下面例子,点击连接不会跳转,只会弹出警告.
<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>
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Event.preventDefault()
在事件里头取消事件的默认动作。
例如下面例子,点击连接不会跳转,只会弹出警告.
The text was updated successfully, but these errors were encountered: