iFrame / Javascript不会更新

时间:2013-12-16 20:43:29

标签: javascript php html iframe

我实际上是在学习Javascript,尤其是iframe。

所以我制作了一个表单,该表单由request.php检查,然后通过target : framename.php发送到我的iframe,其中包含更新我的iframe的功能。

问题是我的框架没有更新,我没有控制台消息。

我给你看了代码:

的index.php

<form id = "welcome" action = "request.php" target = "hello" method="post">
    <label for = "welcomeMsg"> Message : </label>
    <input id = "welcomeMsg" name = "welcomeMsg" type = "text"/>
    <input type = "submit" value = "send" />
</form>



<iframe src = "hello.php" id = "hello" name = "hello"></iframe>

<script>

function sayMsg(welcomeMsg){

    var frame  = document.getElementById('hello').contentDocument;
    frame.innerHTML = welcomeMsg;
}

</script>

request.php

<script>
window.top.window.sayMsg("<?php echo $_POST['welcomeMsg']; ?>");
</script>

hello.php(iframe)

<p id = "mess"> Hello </p>

你可能会想'为什么你使用html页面作为iframe因为id会起作用',这是因为我会自定义这个hello.php。

0 个答案:

没有答案