JS彈出對話方塊函數alert(),confirm(),prompt()

來源:互聯網
上載者:User

標籤:

1,警告訊息框alert()

       alert 方法有一個參數,即希望對使用者顯示的文本字串。該字串不是 HTML 格式。該訊息框提供了一個“確定”按鈕讓使用者關閉該訊息框,並且該訊息框是強制回應對話方塊,也就是說,使用者必須先關閉該訊息框然後才能繼續進行操作。 

2,確認訊息框confirm()

       使用確認訊息框可向使用者問一個“是-或-否”問題,並且使用者可以選擇單擊“確定”按鈕或者單擊“取消”按鈕。confirm 方法的傳回值為 true 或 false。該訊息框也是強制回應對話方塊:使用者必須在響應該對話方塊(單擊一個按鈕)將其關閉後,才能進行下一步操作。 

3,提示訊息框prompt()

       提示訊息框提供了一個文字欄位,使用者可以在此欄位輸入一個答案來響應您的提示。該訊息框有一個“確定”按鈕和一個“取消”按鈕。如果您提供了一個輔助字串參數,則提示訊息框將在文字欄位顯示該輔助字串作為預設響應。否則,預設文本為 "<undefined>"。 與alert( ) 和 confirm( ) 方法類似,prompt 方法也將顯示一個模式訊息框。使用者在繼續操作之前必須先關閉該訊息框 。

4,執行個體

<html><head><script type="text/javascript">    function disp_alert(){        window.alert("Hello World!");    }    function disp_confirm(){        var truthBeTold = window.confirm("年滿18歲請繼續!");        if(truthBeTold){            window.alert("成人影片!");        }else{            window.alert("少兒不宜!");        }    }    function disp_prompt(){        var name = window.prompt("Please enter your name","");        if (name!=null && name!=""){            window.alert("Hello " + name + "!");        }    }</script></head><body><input type="button" onclick="disp_alert()" value="alert button" /><input type="button" onclick="disp_confirm()" value="confirm button" /><input type="button" onclick="disp_prompt()" value="Display a prompt box" /></body></html>

  

JS彈出對話方塊函數alert(),confirm(),prompt()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.