我有一个jQuery对话框,当您单击图像时,对话框会打开,您必须确认是否要删除。是或否。
我用三个文件执行此操作:
主文件index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Aircrafts</title>
<link rel="stylesheet" type="text/css" href="../../../lib/css/style.css">
<link rel="stylesheet" href="../../../lib/css/flick/jquery.ui.all.css">
<script src="../../../lib/js/jquery.js"></script>
<script src="../../../lib/js/ui/jquery.ui.button.js"></script>
<script src="../../../lib/js/ui/jquery.ui.core.js"></script>
<script src="../../../lib/js/ui/jquery.ui.widget.js"></script>
<script src="../../../lib/js/ui/jquery.ui.mouse.js"></script>
<script src="../../../lib/js/ui/jquery.ui.button.js"></script>
<script src="../../../lib/js/ui/jquery.ui.draggable.js"></script>
<script src="../../../lib/js/ui/jquery.ui.position.js"></script>
<script src="../../../lib/js/ui/jquery.ui.resizable.js"></script>
<script src="../../../lib/js/ui/jquery.ui.dialog.js"></script>
<script>
$(function() {
$( "#loadingdialog" ).dialog({
autoOpen: false,
width: 300,
height: 65
});
$("#loadingdialog").dialog('widget').find(".ui-dialog-titlebar").hide();
$("#loadingdialog").dialog('widget').find(".ui-resizable-se").hide();
$( "#confirmdialog" ).dialog({
autoOpen: false
});
$("#confirmdialog").dialog('widget').find(".ui-resizable-se").hide();
});
if (window.XMLHttpRequest)
{
ajax=new XMLHttpRequest();
}
else
{
ajax=new ActiveXObject("Microsoft.XMLHTTP");
}
function confirmdelete(str){
var loading = $("#loadingdialog").dialog('open');
var confirm = $("#confirmdialog");
confirm.load("./confirm_dialog.php?icao="+str, function(){
loading.dialog('close');
confirm.dialog('open');
$('#yes').blur();
});
}
function remove(str){
var loading = $("#loadingdialog").dialog('open');
confirm.load("./delete_aircarft.php?icao="+str, function(){
refreshTable(function(){loading.dialog('close');});
refreshTable(function(){$('#result').fadeIn(); document.getElementById('result').innerHTML=ajax.responseText;});
setTimeout(function() { $('#result').fadeOut() }, 5000);
});
}
function close(){
$("#confirmdialog").dialog('close');
}
</script>
</head>
<body>
<div id="result"></div></br>
<div id="loadingdialog"><center><p><img src="../../../lib/images/loading.gif"></center></p></div>
<div id="confirmdialog"></div>
<img src="../../../lib/images/cross.png" onclick="confirmdelete('B737')">
</body>
</html>
confirm_dialog.php:
<script>
$("#yes")
.button()
.click(function(event) {
});
$("#no")
.button()
.click(function(event) {
});
</script>
<h2><font face="century Gothic">Are you sure?</font><h2><hr size="1">
                    
<tr><td><input id="yes" type="submit" value="Yes" onclick="remove('<?php echo $_GET["icao"]; ?>')"></td>   <td><input id="no" type="submit" value="No" onclick="close()"/></td></tr>
还有delete_aircraft.php(目前此文件只显示获取的ICAO,以后我会准备删除,但这不是问题):
<?php echo $_GET["icao"]; ?>
问题是当对话框打开时,您可以单击是或否,但如果单击是或否则没有任何操作。
答案 0 :(得分:3)
为什么不使用Dialog的内置按钮?
$( "#confirmdialog" ).dialog({
autoOpen: false,
buttons: {
"Yes": function() {
// YOUR ACTION HERE //
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
编辑:更新您的remove
函数以使用按钮和所需变量加载对话框:无需加载外部PHP文件。此外,在创建对话框时设置动画 - 不需要所有这些额外的处理程序。
$( "#confirmdialog" ).dialog({
autoOpen: false,
show: "fade", // Fade In
hide: "fade" // Fade Out
});
function remove(str){
// Set the button action. str is available here
$( "#confirmdialog" ).dialog("option", "buttons", {
"Yes": function() {
// YOUR ACTION HERE //
// str has the value of your "icao" variable
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
});
// Open the dialog
$( "#confirmdialog" ).dialog("open");
}
答案 1 :(得分:2)
那是因为你没有放任何东西..
$("#yes")
.button()
.click(function(event) {
// do something
});
$("#no")
.button()
.click(function(event) {
// do something
});