国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

JavaScript cancels browser default action

Default action refers to the operation performed by the browser that is not explicitly specified by the user. For certain HTML tags, the browser always has a default action.

http://www.baidu.com

Click the link above, and the browser will pop up a window to enter the Baidu homepage. This action is the default action of the browser: clicking an <a> tag will redirect you to the target page.

Other browser default actions include clicking the submit button to submit the form, clicking the reset button to reset the form, moving the mouse to an element with the title attribute to display a prompt, etc.

The browser's default action can be canceled through JavaScript.

For browsers that follow the W3C specification, use the preventDefault() method of the event object to cancel the default action; however, IE8.0 and below does not support this method. It assigns false to the returnValue attribute of the event object. to cancel the default action.

Cancel the default action of the <a> tag.

<html>
<head>
<title>取消<a>標(biāo)簽的默認(rèn)動(dòng)作</title>
</head>
<body>
<a id="demo" href="http://www.baidu.com" target="_blank">點(diǎn)擊這里試試</a>
<script type="text/javascript">
    document.getElementById("demo").onclick=function(e){
        var eve = e || window.event;
        try{  // 使用 try...catch 語(yǔ)句避免瀏覽器出現(xiàn)錯(cuò)誤提示
            eve.preventDefault();  // 非 IE 瀏覽器
        }catch(e){
            eve.returnValue = false;  // IE8.0 及其以下版本
        }
    }
</script>
</body>
</html>


Continuing Learning
||
<html> <head> <title>取消<a>標(biāo)簽的默認(rèn)動(dòng)作</title> </head> <body> <a id="demo" href="http://www.baidu.com" target="_blank">點(diǎn)擊這里試試</a> <script type="text/javascript"> document.getElementById("demo").onclick=function(e){ var eve = e || window.event; try{ // 使用 try...catch 語(yǔ)句避免瀏覽器出現(xiàn)錯(cuò)誤提示 eve.preventDefault(); // 非 IE 瀏覽器 }catch(e){ eve.returnValue = false; // IE8.0 及其以下版本 } } </script> </body> </html>
submitReset Code