2013-01-15 38 views
2

正在開發Web應用程序,當我嘗試驗證並提交表單時,它的工作正常。jquery是/否對話框問題

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

其沒有得到進入下一個步驟我的意思是沒有提交。但是如果我點擊沒有它是重點。我在這裏做錯了什麼?請幫我任何一個?提前致謝。

回答

0

我認爲$(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 
}); 
+0

嘿伯恩哈德, 感謝您的快速回復,當我使用「ID =‘對話’」中提到,未來的警報,但仍同樣的問題。 當我使用$('#dialog')。dialog(「close」)這樣的偶數對話框也沒有關閉。 謝謝 –

+0

在我的情況下,它正在關閉... – Bernhard