0

我想从现有表单打开新窗口。当我单击表单中的新窗口时,应打开新表单并输入值的结果,但新窗口表单正在打开主页,无法从父表单获取文本框值.

如何使用javascript从父窗口调用弹出窗口中的文本字段输入值?

//currently I'm using following code:
<script type="text/javascript">
function pop_up5() {
  var l_url=window.opener.document.getElementById("name").value;
  window.open(l_url,'''','scrollbars=yes,resizable=no,width=550,height=400');
}
</script>
4

2 回答 2

2

分配window.open()给一个变量,以便您可以访问它的元素。

<form>
    <input type="textbox" id="txt" />
    <input type="button" id="btn" value="Open window" />
</form>

<script>
document.getElementById('btn').onclick = function(){
    var myWindow = window.open();
    myWindow.document.body.innerHTML = document.getElementById('txt').value;
};
</script>
于 2012-12-20T08:40:54.020 回答
1

假设您的文本字段的 id 是myTextField,无论您如何命名。如果它没有 id,则为其设置一个 id。然后,在弹出窗口中,您可以使用 JavaScriptparent.document.getElementById('myTextField').value获取文本字段的值。

于 2012-12-20T08:02:23.863 回答