[英]modal window doesn't close
我的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) {
...............
如果我理解,部分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父級中解析的數據。 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%;">');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.