2010-10-20 39 views
6

我可以在JavaScript中编写自定义确认框,而不是默认的OKCANCEL按钮,显示SAVEDELETE按钮?带自定义按钮的JavaScript确认框

+1

[自定义选择在javascript确认对话框中。](http://stackoverflow.com/questions/1800033/custom-choices-in-javascript-confirm-dialog) – kennytm 2010-10-20 09:12:44

+2

我建议不要使用JavaScripts' confirm( )','alert()'或'prompt()'命令,因为这些命令阻塞了整个浏览器线程(在大多数浏览器中)。您应该使用JavaScript-UI替代方案。 – jwueller 2010-10-20 09:35:33

回答

5

不适用于本地JavaScript确认框。您可以使用模拟对话框的许多JavaScript UI组件之一来完成此操作。

下面是一个例子:http://jqueryui.com/demos/dialog/modal-confirmation.html

我从来没有用过这个您自己的风险所以使用。

+0

你可以举一个工作的例子 – 2010-10-20 09:13:35

3
$('confirm text').dialog(
    { 
     modal:true, //Not necessary but dims the page background 
     buttons:{ 
      'Save':function() { 
       //Whatever code you want to run when the user clicks save goes here 
      }, 
      'Delete':function() { 
       //Code for delete goes here 
       } 
     } 
    } 
); 

这应该可行,但您需要下载或链接到jQuery和jQuery UI库才能运行此操作。