2016-03-17 88 views

回答

2

您可以通過使用confirm實現它,使用的代碼如下:

<button onclick="myFunction()">Try it</button> 
<script> 
function myFunction() { 
confirm("Press a button!"); 
} 
</script> 

上面的例子是非常基本的,如果你的一些設計確認框,然後請craftpip's jquery-confirm希望你喜歡它。

-1

正如別人所說,使用confirm方法。

可以得到確認回調是這樣的:

confirm("Are you sure you want to do this?", function(result) { 
if(result) 
    doSomethingPositive(); 
else 
    doSomethingNegative(); 
}); 
+1

1)不要重複別人已經給出的答案,除非你有東西要添加。 2)這不是你如何使用'confirm()' –

+0

@yourmom這個方法怎麼了?當我創建我的答案時,沒有回調的示例 – henrik123

+2

確認方法沒有任何回調。它根據用戶操作簡單地返回true或false。 – henrikmerlander

1

您可以使用confirm這一點。根據用戶的操作,它將返回truefalse。例如:

var result = confirm("Please confirm this action!") 
if(result) 
    //The user confirmed the action 
else 
    //The user declined the action 
相關問題