我的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;
}
答案 0 :(得分:0)
如果我没错你。原因和解决方案很简单
您的模态容器页面 - 您在其中创建iframe - 具有这些功能吗?
closewindow()和函数plusbutton()
他们旁边也有
$(".add").on("click", function(event) {
...............
如果我理解的话,部分-event catcher-在主html中?
所以你不能指望$(“。add”)。on(“click”,function(event)....由iframe内的按钮触发。
你可以做的就是将$(“。add”)。on(“click”,function(event)转换为函数
chage that
$(".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创建者行中添加一个id $.modal('<iframe if="the_frame" src="' + src + '" style="border:0;width:100%;height:100%;">');