Jquery UI对话框取代javascript确认



我有一堆验证javascript进程与确认。我想使用jquery ui dialog,但是我需要为其余的验证过程返回true。

例如:

var where_to_coupon = confirm(pm_info_msg_013);
      if (where_to_coupon== true) {
      doSubmit=true;
      return doSubmit;

因此,我需要一个函数来用UI对话框替换confirm,拉消息字符串(pm_info_msg_013),并使用我自己的按钮或UI按钮返回验证过程的true。

不知道从哪里开始。

帮助吗?

在jQuery UI对话框中,设置modal选项为true,并使用buttons选项指定主要和次要用户操作

    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: [{
            text: pm_info_msg_013,
            click : function() {    
                $( this ).dialog( "close" );
                // code related to "where_to_coupon== true" goes here
                // submit form
                }
            }, {
            text: "Cancel",
            click: function() {
                $( this ).dialog( "close" );
                doSubmit = false;
                // don't submit form
            }}]
    });

请看这里的演示:http://jqueryui.com/demos/dialog/#modal-confirmation

更新:这将允许您创建多个确认。用法:

function CreateDialog(okText, cancelText, okCallback, cancelCallback) {
        $( "#dialog-confirm" ).dialog({
            resizable: false,
            height:140,
            modal: true,
            buttons: [{
                text: okText,
                click : function() {    
                    $( this ).dialog( "close" );
                    okCallback();
                    }
                }, {
                text: cancelText,
                click: function() {
                    $( this ).dialog( "close" );
                    cancelCallback();
                }}]
            }
        });
// ******* usage #1 ********    
CreateDialog(pm_info_msg_013, "Cancel", function () {
   // where_to_coupon== true
}, function() {
   // where_to_coupon== false
});
function OnConfirmTrue() {
  // do something
}
function OnConfirmFalse() {
  // do something
}
// ******* usage #2 ********
CreateDialog(pm_info_msg_013, "Cancel", OnConfirmTrue, OnConfirmFalse);

我已经为jQuery UI创建了一个名为dialogWrapper的插件,它提供了几个方法,包括一个confirm方法。你可以这样调用它:

$.confirm("Prompt", function(){}, function(){}, {});

第二个和第三个参数分别是单击yes和no按钮时所做的操作。第四个用于附加参数。

点击这里查看:http://code.google.com/p/dialogwrapper/

它不工作像原生JavaScript confirm方法,虽然,因为它是异步的。所以你不能直接用$.confirm覆盖confirm

你听过Trent Richardson的即兴表演吗?

http://trentrichardson.com/Impromptu/

这个jquery插件可以为您提供您正在寻找的提示和确认等控件。

最新更新