例如test.jsp中有一个text字段
<input name="id1" type="text" value="abc" size="40">在Javascript中打开这个页面,然后将这个页面值打印出来
var s=window.open('test.jsp','mywin');
alert(s.document.id1.value);这时产生脚本错误,说s.document.id1.value未定义,Javascript如何才能获取页面中的值呢?谢谢!

解决方案 »

  1.   

      <script type="text/javascript">
      <!--
    var s=window.open('16.htm','mywin');
    alert(s.document.getElementById("id1").value);  //-->
      </script>
      

  2.   

    直接这样够呛。window.open刚打开文件,还没加载完就执行下面的显示其中特定对象的值的语句了。如果加载稍慢一点,都取不到。应该监听onload事件,在其中处理var s=window.open('theforever_csdn.jsp','mywin');
    s.onload=function(){alert(s.document.getElementById("theforever_id1").value);};
      

  3.   

    s.onload=function(){alert(s.document.getElementById("theforever_id1").value);};这个如果有问题的话,试试s.onload=function(){alert(document.getElementById("theforever_id1").value);};我没调试,你试一下就知道用哪个了
      

  4.   

    getElementById绿色辅助工具——《Csdn收音机》帮你轻松掌握Csdn最新动向!