Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将数据从父html窗口传递到弹出窗口_Javascript_Html_Popup - Fatal编程技术网

Javascript 如何将数据从父html窗口传递到弹出窗口

Javascript 如何将数据从父html窗口传递到弹出窗口,javascript,html,popup,Javascript,Html,Popup,我试图将一些数据从父窗口传递到html中的弹出窗口 下面是我的代码- <html> <head> <script type="text/javascript"> function init() { popupWin = window.open('','popupWin',''); popupWin.document.writeln('<html><head><title>test</title>&

我试图将一些数据从父窗口传递到html中的弹出窗口

下面是我的代码-

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>

函数init()
{
popupWin=窗口打开(“”,'popupWin',“”);
popupWin.document.writeln('test');
popupWin.document.close();
popupText=popupWin.document.getElementById(“popupTextBox”);
parentText=document.getElementById(“parentTextBox”);
}
函数transferText()
{
popupText.value=parentText.value
}
但不知何故,我无法用上述代码将文本框数据传递到弹出窗口。这有什么问题吗


一般来说,我试图将一些数据从父窗口传递到弹出窗口。

您忘记调用
transferText()

调用
transferText()
后,文本被传输

<html>
<head>
<script type="text/javascript">
function init()
{
    popupWin = window.open('','popupWin','');
    popupWin.document.writeln('<html><head><title>test</title></head><body><form><input type="text" id="popupTextBox"/></form></body></html>');
    popupWin.document.close();
    popupText = popupWin.document.getElementById("popupTextBox");
    parentText = document.getElementById("parentTextBox");
    transferText();
}
function transferText()
{
    popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox"/>
<input type="button" onclick="init();"/>
</body>
</html>

函数init()
{
popupWin=窗口打开(“”,'popupWin',“”);
popupWin.document.writeln('test');
popupWin.document.close();
popupText=popupWin.document.getElementById(“popupTextBox”);
parentText=document.getElementById(“parentTextBox”);
transferText();
}
函数transferText()
{
popupText.value=parentText.value
}

这可能会有帮助,调用方法的实际流程应该是什么?你能提供完整的语法代码吗。谢谢,有什么相反的方法吗?是否将数据从弹出窗口传递到父窗口?