<!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>