繁体   English   中英

模态窗口没有关闭

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM