js confirm()方法的使用方法執行個體

來源:互聯網
上載者:User

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

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

下面我們通過這兩個小例子,來瞭解一下它的使用方法吧:
複製代碼 代碼如下:
<html>
<head>
<title>confrim 的使用方法</title>
<script type="text/javascript">
function clear1()
{
 if(confirm("確定要清空資料嗎?"))
 {
 document.main.text1.value="";
 }
}
</script>
</head>
<boty>
<form name="main">
<input type="text" name="text1"/>
<input type="button" name="submit" value="資料清空" onclick="return clear1()"/>
</form>
</body>
</html>

<html>
<head>
<title>js confirm</title>
<script>
function begin()
{
 var a=confirm("郭楊和小代是好朋友嗎?");
 if(a==true)
 {
 /*document.write("恭喜你答對了!");*/
 alert("恭喜你答對了!");
 begin();
 }
 else
 {
 /*document.write("你真是豬,這麼簡單的問題都答不對!");*/
 alert("你真是豬,這麼簡單的問題都答不對!");
 begin();
 }
 }
</script>
</head >
<body onload="begin()">
</body>
</html>

聯繫我們

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