Php 如何获得在jQuery确认对话框上执行操作的按钮?
我有一个jQuery对话框,当你点击一个图像时,对话框打开,你必须确认是否要删除。是或否 我使用三个文件执行此操作: 主文件index.php:Php 如何获得在jQuery确认对话框上执行操作的按钮?,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,我有一个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">
<!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_airpair.php目前这个文件只显示了国际民航组织获得的信息,将来我将准备删除它,但这不是一个问题:
<?php echo $_GET["icao"]; ?>
问题是当对话框打开时,您可以单击“是”或“否”,但如果单击“是”或“否”,则没有任何操作。这是因为您没有在那里放置任何内容
$("#yes")
.button()
.click(function(event) {
// do something
});
$("#no")
.button()
.click(function(event) {
// do something
});
那是因为你没有把任何东西放在那里
$("#yes")
.button()
.click(function(event) {
// do something
});
$("#no")
.button()
.click(function(event) {
// do something
});
为什么不使用对话框的内置按钮
$( "#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");
}
为什么不使用对话框的内置按钮
$( "#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");
}
将操作放入为yes和noOk添加的空单击处理程序中,但这不是问题所在@user1972864所说的问题是什么都没有发生。你还没有实现任何东西。所以这是正常的行为。而且,当脚本执行时,按钮不在DOM中。需要准备好文件或类似文件。就我个人而言,与其准备文档,不如委托监听某种类型的父元素。请您将我需要的代码放入修复它的程序中?将操作放入您为yes和noOk添加的空单击处理程序中,但这不是问题所在@user1972864所说的问题是什么都没有发生。你还没有实现任何东西。所以这是正常的行为。而且,当脚本执行时,按钮不在DOM中。需要准备好文件或类似文件。就我个人而言,与其准备文档,不如委托监听某种类型的父元素。请您输入我需要的代码来修复它?这不完全是问题所在。当然,什么也没做。但还有一个问题是,脚本是在构建DOM之前执行的,节点可能没有绑定到它们的事件。我认为问题还可能是,在创建处理程序时,“是”和“否”按钮不存在。脚本应该移到HTML的下面,或者在属性中添加defer。这不完全是问题所在。当然,什么也没做。但还有一个问题是,脚本是在构建DOM之前执行的,节点可能没有绑定到它们的事件。我认为问题还可能是,在创建处理程序时,“是”和“否”按钮不存在。脚本应该移到HTML的下面,或者添加defer到属性。因为我需要用按钮发送ICAO。最后文件中的国际民航组织是在PHP中!好的,我明白了。在这种情况下,将块移动到HTML下方,或将其更改为。。。这应该行得通。虽然在打开对话框时,您看起来有这个值,所以您根本不需要将它传递给PHP。请参见str:confirm.load./delete_aircarft.PHP?icao=+strDoes该页面包含jQuery?好的。对我来说,看起来您根本不需要加载confirm_dialog.php,而且可以从javascript直接完成。我会用那个密码更新我的答案。因为我需要用按钮发送国际民航组织。最后文件中的国际民航组织是在PHP中!好的,我明白了。在这种情况下,将块移动到HTML下方,或将其更改为。。。这应该行得通。虽然在打开对话框时,您看起来有这个值,所以您根本不需要将它传递给PHP。请参见str:confirm.load./delete_aircarft.PHP?icao=+strDoes该页面包含jQuery?好的。对我来说,看起来您根本不需要加载confirm_dialog.php,而且可以从javascript直接完成。我会用那个代码更新我的答案。