用 window.open 打开一个页面,那这个页面总需要一定的时间来加载吧,页面都没有加载完,当然你去调用页面里的对象时就会出错喽。加了一个 alert() 也就是起到了这个延迟的作用。你应该把你的逻辑代码写在页面的 onload 里:
<script type="" language="javascript">
function openEditWindow(){
  var subWindow = window.open('editCategory.jsp','','width=300,height=150');
  subWindow.attachEvent("onload", function(){
    document.getElementById("testText").value='test';
  });
}
</script>

解决方案 »

  1.   

    上面的这段代码没有测试,可能是取window不正确吧:<script type="" language="javascript">
    var subWindow;
    function openEditWindow(){
      subWindow = window.open('editCategory.jsp','','width=300,height=150');
      mm()
    }
    function mm()
    {
      if(subWindow.document.readyState=="complete")
         subWindow.document.getElementById("testText").value='test';
      else setTimeout("mm()", 100);
    }
    </script>
      

  2.   

    在open的窗口里的body的onload事件里调用opener的函数来写就可以了
      

  3.   

    script type="" language="javascript">
    function openEditWindow(){
      var subWindow = window.open('editCategory.jsp?id='aa'','','width=300,height=150');
      subWindow.document.getElementById("testText").value='test';
    }
    在editCategory.jsp中
    <%
    String StrTemp=request.getParameter("id");
    %>
    <input type="text" name="text" value="<%=StrTemp%>">
    楼主你看一看我这段代码能不能给你一点小小的提示