JS中 confirm() 方法

前言

環境: window 10,google 瀏覽器

測試代碼

<html>
    <!--
    
        測試肯定框,若是點 "是" ,則返回 true,這樣就觸發 a 標籤的 href 屬性
        反之,則什麼也不作,不會觸發 a 標籤的 href 屬性。
        
    -->
    <head>
        <title>測試 </title>
    </head>
    <body>
        <a id="button" href="http://www.baidu.com" onclick="fun()">
            點擊跳轉到百度界面
        </a>
    </body>
</html>
<script>
    function fun(){
        
        
        return window.confirm();
        
        
    }
    alert(window.confirm("訪問百度嗎?"));
</script>

效果圖

總結

肯定框,若是點 "是" ,則返回 true,這樣就觸發 a 標籤的 href 屬性
反之,則什麼也不作,不會觸發 a 標籤的 href 屬性。html

相關文章
相關標籤/搜索