我的 php 脚本中有两个函数,它们位于 QandA2Table.php 中,但它们的按钮位于 previousquestions.php 页面中,因为模态窗口显示该页面的详细信息。
无论如何,我下面有两个按钮,分别是“关闭”按钮和“添加”按钮:
<div id="previouslink">
<button type="button" id="close" onclick="return parent.closewindow();">Close</button>
</div>
<?php
$output = "";
while ($questionrow = mysql_fetch_assoc($questionresult)) {
$output .= "
<table>
<tr>
<td id='addtd'><button type='button' class='add'>Add</button></td>
</tr>";
}
$output .= " </table>";
echo $output;
}
}
?>
我遇到的问题是关闭模态窗口。当我单击“关闭”按钮时,它会关闭模态窗口,这很好,但是如果我单击“添加”按钮,它不会关闭模态窗口。这是为什么?
下面是两个按钮的功能:
function closewindow() {
$.modal.close();
return false;
}
$(".add").on("click", function(event) {
console.log("clicked");
var theQuestion = $("td:first-child", $(this).parent()).text();
if ($('.activePlusRow').length > 0) {
$('.activePlusRow').next('.textAreaQuestion').val(theQuestion);
}
parent.closewindow();
return true;
});
下面是iframe:
function plusbutton() {
// Display an external page using an iframe
var src = "previousquestions.php";
$.modal('<iframe src="' + src + '" style="border:0;width:100%;height:100%;">');
return false;
}
最佳答案
如果我没有误会你的话。原因和解决方法很简单
您的模态容器页面(您在其中创建 iframe)具有这些功能吗?
closewindow() 和函数 plusbutton()
除了他们还有你
$(".add").on("click", function(event) {
...............
部分 -event catcher- 在主 html 中,如果我理解正确的话?
所以你不能期望 $(".add").on("click", function(event) .... 被 iframe 内的按钮触发。
你可以简单地做的是将 $(".add").on("click", function(event) 转换为函数
改变那个
$(".add").on("click", function(event) {
console.log("clicked");
var theQuestion = $("td:first-child", $(this).parent()).text();
if ($('.activePlusRow').length > 0) {
$('.activePlusRow').next('.textAreaQuestion').val(theQuestion);
}
parent.closewindow();
return true;
});
到
function add_function {
console.log("clicked");
//通过添加帧 ID 引用来更改此部分以适应您的内容层次结构。 //我不知道你将在 td:first-childs parent 中解析的数据。 var theQuestion = document.frames["the_frame"].$("td:first-child", $(this).parent()).text();
if ($('.activePlusRow').length > 0) {
$('.activePlusRow').next('.textAreaQuestion').val(theQuestion);
}
parent.closewindow();
return true;
}
并在 iframe 内容中更改这一行
<td id='addtd'><button type='button' class='add'>Add</button></td>
到
<td id='addtd'><button type='button' class='add' onclick="parent.add_function();" >Add</button></td>
并在 plusbutton 函数的 iframe creator 行中添加一个 id
$.modal('<iframe if="the_frame" src="' + src + '" style="border:0;width:100%;height:100%;">');
关于php - 模态窗口不关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10816698/