2

这就是我所拥有的

    <html>
    <head>
    </head>
    <body>
    <iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>
    <div id="hiddendiv" style="display:none">
    some text
    </div>
    </body></html>

这就是我在 iframe 中的表单提交后想要得到的结果(通过输入或单击按钮提交,我不在乎,因为表单只有 1 个字段)

    <html>
    <head>
    </head>
    <body>
    //I want this iframe to become display:none or to be deleted
    /*<iframe id="myiframe">
    <form id= "myform" action="submit.php" method="POST">
    <input type="submit">
    </form></iframe>*/
    //and this div to be showed
    <div id="hiddendiv" style="display:">
    some text
    </div>
    </body></html>

谁能帮忙,谢谢

我有答案,但我必须等待 8 小时才能发布,所以我编辑了最初的问题,如果你愿意,你可以将其验证为答案

知道了

<html>
<head>
</head>
<body>
<script>

function closeIframe() {
var iframe = document.getElementById('myiframe');
iframe.parentNode.removeChild(iframe);
document.getElementById("hiddendiv").style.display="";
}

</script>
<iframe id="myiframe">
<form id= "myform" action="submit.php" method="POST">
<input type="submit">
</form></iframe>
<div id="hiddendiv" style="display:none">
some text
</div>
</body></html>

在 submit.php 中返回的是这个

echo '<script type="text/javascript">';
echo 'parent.closeIframe()';
echo '</script>';
4

2 回答 2

1

如果来自同一域,请将其添加到 submit.php 并提取表单以放入 iframe 您需要

<iframe src="form.html"></iframe>

演示

<script>
top.document.getElementById("myiframe").style.display="none";        
top.document.getElementById("hiddendiv").style.display="block";
</script>
于 2013-02-01T11:51:23.307 回答
1
<html>
<head>
</head>
<body>
<script>

function closeIframe() {
var iframe = document.getElementById('myiframe');
iframe.parentNode.removeChild(iframe);
document.getElementById("hiddendiv").style.display="";
}

</script>
<iframe id="myiframe">
<form id= "myform" action="submit.php" method="POST">
<input type="submit">
</form></iframe>
<div id="hiddendiv" style="display:none">
some text
</div>
</body></html>

在 submit.php 中返回的是这个

echo '<script type="text/javascript">';
echo 'parent.closeIframe()';
echo '</script>';
于 2013-02-10T16:02:10.010 回答