2016-09-09 182 views
1

我想生成一個對話框,從用戶獲取密碼,這裏有一點我的代碼。jquery對話框不顯示

<html> 
<head> 
<script type="text/javascript" src="jquery.min.js"></script> 
<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"> 
<script src="http://code.jquery.com/jquery-1.10.2.js"></script> 
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
</head> 

<body> 
<input type='button' id='btnDelete' name='btnDelete' value='Delete' onclick='deleteRecord(".$row['ID'].")'/> 
<div id="delete-dialog" style="display: none;" title="Delete Record"> 
    <label>Please type in admin's password:</label></br> 
    <input type='password' size='25' id='inpAdminPassword'/>   
</div> 
</body> 
</html> 

JS

function deleteRecord(ID){ 
var answer = confirm("Are you sure you want to delete this record?"); 
if(answer == true){ 
    $("#delete-dialog").dialog("open"); 
    } 
} 

$(document).ready(function() { 
$("#delete-dialog").dialog({ 
    autoOpen: false, 
}); 

不知何故,該對話框不顯示,什麼是必須丟失?

我也試過幷包含這段代碼,但它仍然無效。

$(document).ready(function() { 
$("#delete-dialog").dialog({ 
    autoOpen: false, 
}); 
$("#delete-dialog").dialog({ 
    modal: true, 
    autoOpen: false, 
    height: 255, 
    width: 300, 
    buttons: { 
     "Delete": function() { 
      var password = document.getElementById('sessionPW').value; 
      var adminpw = document.getElementById('inpAdminPassword').value; 
      alert(password); 
      if(password == adminpw){ 
       window.location = "deleteThreat.php?threatID="+ID; 
      } 
     }, 
     Cancel: function() { 
      $(this).dialog("close"); 
      } 
     } 
    }); 
}); 

回答

0

我只是想你的第一個解決方案,使確認這樣的工作對我來說:

JS:

$("#delete-dialog").dialog({ 
     autoOpen: false, 
    }); 

    $("#open").click(function() { 

     if (confirm("are you sure?")) { 
      $("#delete-dialog").dialog("open"); 
     } 


    }); 

HTML:

  <div id="delete-dialog" style="display: none;" title="Delete Record"> 
       <label>Please type in admin's password:</label></br> 
       <input type='password' size='25' id='inpAdminPassword'/>   
      </div> 

      <button id="open" >Open</button> 
+0

你把CSS代碼?對話框仍然不顯示。 js代碼是否在ready函數中? – camille

+0

是不是內部準備好的功能,我不把css – AitorFDK

+0

它仍然不顯示T.T如何jquery-ui版本? – camille