标签:
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <a href="http://www.baidu.com">百度</a> <a href="http://www.qq.com" onclick = "return f1()">腾讯</a> <a href="http://www.qq.com" onclick="javascript:return confirm(‘确认要删除吗?‘)">删除</a> <form action="http://www.taobao.com" method="post" > 用户名: <input type="text" name="uesrname" /> <input type="submit" value="提交" /> </form> <script type="text/javascript"> function f1(){ console.log(‘not‘); return false; } var a = document.getElementsByTagName(‘a‘)[0]; a.onclick = function(){ console.log(‘NOT---A‘); return false; } var forms = document.getElementsByTagName(‘form‘)[0]; /* W3C浏览器下的 */ /* forms.addEventListener(‘submit‘,function(evt){ console.log(‘not----form‘); evt.preventDefault(); }); */ /* IE浏览器下的 */ forms.attachEvent(‘onsubmit‘,function(){ console.log( ‘表单提交了‘ ); window.event.returnValue = false; }) </script> </body> </html>
夺命雷公狗---在js里阻止a标签的跳转和form表单的跳转
标签:
原文地址:http://www.cnblogs.com/leigood/p/5563507.html