模式窗口不会关闭


modal window doesn't close

我的php脚本中有两个函数,它们放在QandA2Table中.php但它们的按钮放在上一个问题.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 - 具有这些功能吗?

关闭窗口() 和函数加号按钮()

在他们旁边,你还有

$(".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>

并在加号按钮功能处将 ID 添加到 iframe 创建器行

 $.modal('<iframe if="the_frame" src="' + src + '" style="border:0;width:100%;height:100%;">');