【问题标题】:jquery yes/no Dialog issuejquery是/否对话框问题
【发布时间】:2012-12-29 08:30:48
【问题描述】:

我正在开发网络应用程序,当我尝试验证并提交这样的表单时,它工作正常。

                var res = confirm ("Are u want to continue?")
                if (res)
                {
                    var stra_validator = $("#form").validate(form_rule);
                    stra_validator.reset();
                    return stra_validator.form();

                }else{
                    $('#someID').focus();
                    return false;
                }

但是当我尝试使用 jQuery 对话框时,我是这样使用的

                      var btns = {};
                      btns['Yes'] = function(){ 
                          $(this).dialog("close");

                          var stra_validator = $("#form").validate(form_rule);
                    stra_validator.reset();
                    return stra_validator.form();// continue the process 
                      };
                      btns['No'] = function(){ 
                          $(this).dialog("close");
                                     $('#someID').focus();
                    return false;
                      };
                      $("<div></div>").dialog({
                        autoOpen: true,
                        title: 'Condition',
                        modal:true,
                        buttons:btns
                      });

它没有继续下一步我的意思是不提交。但是,如果我单击“否”,则它正在聚焦。我在这里做错了什么?请帮帮我吗?提前致谢。

【问题讨论】:

    标签: jquery jquery-ui jquery-dialog confirm


    【解决方案1】:

    我认为 $(this).dialog() 在按钮上下文中是错误的。

    试试这个:

    var btns = {};
    btns['Yes'] = function() {
    
      // Here you have to reference the real dialog
      $('#dialog').dialog("close");
      alert('come here');
      var stra_validator = $("#form").validate(form_rule);
      stra_validator.reset();
    
      return stra_validator.form();
      // continue the process
    };
    btns['No'] = function() {
      $('#dialog').dialog("close");
      $('#someID').focus();
    
      return false;
    };
    
    // Never created a div on the fly but it's working well and I just added an ID
    $('<div id="dialog"></div>').dialog({
    autoOpen : true,
    title : 'Condition',
    modal : true,
    buttons : btns
    });
    

    【讨论】:

    • 嗨,Bernhard,感谢您的快速回复,当我使用“id='dialog'”时提到,警报来了,但仍然是同样的问题。当我像这样使用 $('#dialog').dialog("close") 时,即使对话框也没有关闭。谢谢
    猜你喜欢
    • 2011-05-28
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多