繁体   English   中英

将value元素设置为window.open()调用的其他页面

[英]Set value element to a other page called by window.open()

我正在努力实施这个案子,我非常感谢你的帮助。

更新:

page1.html

<html>
<head>
<title></title>
</head>
<body >
<form>  
    filled value : <input type="text" id="one">
</form>
</body>
</html>

page2.html

<form>
    <input type="button" onclick='go();' value='call_page1'/>
</form>

第一次尝试:第1页显示,但未设置值

 <script>
 function go(){
          var newWindow;
             newWindow= window.open('page1.html', 'form', 'width=400,height=350');
         newWindow.document.getElemetById('one').value='xxx';

}
   </script>

第二次尝试:第1页甚至没有显示出来

     <script>
    function go(){

     var detailsWindow;
        detailsWindow = window.open('page1.html', 'form', 'width=400,height=350');

        detailsWindow.onload = function{
    document.getElementById('one').value='test';
    }
    }
<script>

问:设置value “的价值page1.html ,当它被称为在page2.html

或者如果有另一种选择(但请放轻松我,我只是学习这些东西)。 I don't use JQuery ,如果有不清楚的地方,我很高兴听到它。

看待。

// page1.html

<script>
var newWindow = window.open('page2.html', 'formUntukUpdate', 'width=400,height=350');
newWindow.onload = function(){
    newWindow.document.getElementById('one').value = 'ok 2';
};
</script>

// page2.html

<input type="text"  id="one" value="ok" />

首先,javascript是大小写的,并且缺少n 所以用getElemetByID替换getElementById

其次是代码立即执行,不等待页面加载。 您必须将您的代码包装在window.onload

newWindow.onload = function(){
     newWindow.document.getElementById('one').value='xxx';
}

更新中有3个错误:

  1. function detailsWindow.onload = function必须声明detailsWindow.onload = function()才能工作。
  2. 您的结束脚本必须从<script>替换为</script>
  3. 你在document.getElementById('one').value = 'test';中缺少detailsWindow document.getElementById('one').value = 'test'; 它必须是detailsWindow.document.getElementById('one').value = 'test';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM