JS中 confirm()方法的使用?

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   java   ar   for   

confirm() 方法用於顯示一個帶有指定訊息和 OK 及取消按鈕的對話方塊。

如果使用者點擊確定按鈕,則 confirm() 返回 true。如果點擊取消按鈕,則 confirm() 返回 false。

在使用者點擊確定按鈕或取消按鈕把對話方塊關閉之前,它將阻止使用者對瀏覽器的所有輸入。在調用 confirm() 時,將暫停對 JavaScript 代碼的執行,在使用者作出響應之前,不會執行下一條語句,相當於alert();方法

<input type="button" name="save" value="儲存" onclick="if((confirm(‘確定要提交嗎?‘))) this.form.onsubmit();"/>  

  執行個體:

<html><head><title>confrim 的使用方法</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">function clear1(){ if(confirm("確定要清空資料嗎?")) { document.main.text1.value=""; }}</script></head><boty><form name="main"><input type="text" name="text1" value="資料清空"/><input type="button" name="submit" value="資料清空" onclick="return clear1()"/></form></body></html>

  onclick="return clear()" 與onclick="clear()"的區別? 前者驗證成功後提交 後者,直接提交

 

JS中 confirm()方法的使用?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.