时间:2020-12-14 14:27:30 | 栏目:JavaScript代码 | 点击:次
js阻止浏览器默认行为的简单实例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <a id="a1" href="http://www.baidu.com">百度</a> <script> function stopDefault(e){ //非IE if(e && e.preventDefault) e.preventDefault(); //IE else window.event.returnValue = false; } window.onload = function(e){ var a1 = document.getElementById("a1"); a1.onclick = function(e){ stopDefault(e); } }; </script> </body> </html>