Jquery UI对话框代替javascript确认 [英] Jquery UI dialog in place of javascript confirm

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

问题描述

我有一堆验证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按钮返回真实的验证过程。



不知道从哪里开始。



帮助?

解决方案

在jQuery UI对话框中,设置 modal 选项为true,并使用按钮选项指定主用户和辅助用户操作。

  $(#dialog-confirm).dialog({
resizable:false,
height:140,
modal:true,
按钮: {
text:pm_info_msg_013,
click:function(){
$(this).dialog(close);
//与where_to_coupon == true相关的代码去这里
//提交表单
}
},{
文本:取消,
点击:function(){
$(this).dialog(close);
doSubmit = false;
//不提交表单
}}]
});

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



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

  function CreateDialog(okText,cancelText,okCallback,cancelCallback){
$(#dialog-confirm ).dialog({
resizable:false,
height:140,
modal:true,
按钮:[{
文本:okText,
点击:function(){
$(this).dialog(close);
okCallback();
}
},{
text:cancelText,
click:function(){
$(this).dialog(close);
cancelCallback();
}}]
}
} );

// *******使用#1 ********
CreateDialog(pm_info_msg_013,取消,function(){
// where_to_coupon == true
},function(){

// where_to_coupon == false
});

函数OnConfirmTrue(){
//做某事
}

函数OnConfirmFalse(){
//做某事
}

// *******用法#2 ********

CreateDialog(pm_info_msg_013,取消,OnConfirmTrue,OnConfirmFalse) ;


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.

For example:

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

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.

Not sure where to start with this one.

help?

解决方案

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
            }}]
    });

See the demo here: http://jqueryui.com/demos/dialog/#modal-confirmation

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆