2014-04-29 123 views
0

我在頁面打開時顯示一個對話框。但問題是當我點擊對話框的其中一個按鈕時,對話框窗口沒有關閉。我不知道爲什麼。對話框沒有關閉點擊按鈕

這裏是我的代碼:

$(document).ready(function() { 
    var x=$('#loginstatus').val(); 
    if(x==1){ 
     $("#dialog").html("Do You Want to go for Face Recognition and Detection?"); 
     $("#dialog").dialog({ 
      autoOpen: true, 
      modal: true, 
      title: "Permission for Face Recognition", 
      width: 600, 
      height: 300, 
      resizable: false, 
      buttons: { 
       "Yes,Why Not": function() { 
        $(this).dialog("close"); 
        callback("1"); 
       }, 
       "No,Thanx": function() { 
        $(this).dialog("close"); 
        callback("2"); 
       } 
      } 
     }); 
    } 
}); 

,而在HTML我有對話框的div和其他必要的投入。

的Html

<div name="dialog" id="dialog"></div> 
<input type="hidden" name="loginstatus" id="loginstatus" value="<%=firstlogin%>"/> 
+0

你的HTML看起來像什麼? – mcphersonjr

+0

@Cedric我加了html部分也是 – user3522121

+2

你的代碼有效。 jsFiddle http://jsfiddle.net/BZH73/1/ – malkassem

回答

-1
$('#dialog').click(function() { 
$('.dialog').hide(); 
}); 
+0

在哪裏可以看到這個代碼?請給我提供詳細信息 – user3522121

+0

將它包裝在''標籤中,並放在'' – Shakesy

0

測試這一點,我做了按鈕的一些變化:

$(document).ready(function() { 
        var x=$('#loginstatus').val(); 
        if(x==1){ 
         $("#dialog").html("Do You Want to go for Face Recognition and Detection?"); 
         $("#dialog").dialog({ 
          autoOpen: true, 
          modal: true, 
          title: "Permission for Face Recognition", 
          width: 600, 
          height: 300, 
          resizable: false, 
          buttons: { 

           "Yes,Why Not": function() { 
           callback("1"); 
           $(this).dialog("close"); 


          }, 
          Cancel: function() { 
          callback("2"); 
          $(this).dialog("close"); 

          } 

          } 

        }); 
        } 
        }); 
0

嘗試

$("#dialog").dialog('close'); 

,而不是

$(this).dialog("close"); 

除非您完全確定範圍,否則不推薦使用this