5

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

例如:

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

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

不知道从哪里开始。

帮助?

4

3 回答 3

10

在 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);
于 2011-08-10T18:02:58.930 回答
1

我为 jQuery UI 创建了一个名为 dialogWrapper 的插件,它提供了多种方法,包括一个确认方法。你这样称呼它:

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

第二个和第三个参数分别是单击是和否按钮时要做什么。第四个是附加论点。

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

但是,它不像原生 JavaScriptconfirm方法那样工作,因为它是异步的。所以你不能直接confirm$.confirm.

于 2011-08-10T17:59:44.220 回答
0

你试过 Trent Richardson 的 Impromtu 吗?

http://trentrichardson.com/Impromptu/

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

于 2013-11-22T08:29:10.863 回答