用 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>
<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>
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>
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%>">
楼主你看一看我这段代码能不能给你一点小小的提示