这就是我所拥有的
<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>';
最佳答案
如果来自同一域,请将其添加到submit.php中并提取表单以放入iframe中 你需要
<iframe src="form.html"></iframe>
<script>
top.document.getElementById("myiframe").style.display="none";
top.document.getElementById("hiddendiv").style.display="block";
</script>
关于javascript - 从 iframe 提交表单并在提交后关闭它并显示隐藏的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14645647/