本文介绍了Jquery UI 对话框代替 javascript 确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a bunch of validation javascript processes with confirms. I want to use jquery ui dialog, but I need to return true for the rest of the validation processes.

例如:

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.

So I need a function to replace confirm with a UI dialog, pull the message string (pm_info_msg_013), and use my own buttons or UI buttons to return true for the validation process.

不知道从哪里开始.

帮助?

推荐答案

在 jQuery UI 对话框中,将 modal 选项设置为 true,并使用 buttons 选项.

In jQuery UI dialog, set the modal option to true, and specify primary and secondary user actions with the buttons option.

    $( "#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-确认

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

Update:This will allow you to create multiple confirms. Usage:

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 对话框代替 javascript 确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:42