日期:2014-05-18  浏览次数:20801 次

setTimeOut提示缺少对象,应该如何修改啊?

该网页是个框架页,有两个页面,一个是Win1,另一个是Win2。

function PutQuestions(){
  with (parent.Win2.document){
  open();
  write("<html><body>");
  write("第",CurrentQuestion+1,"个问题:<font color=red>");
  write(Questions[CurrentQuestion]+"</font><br>");
  write("<form name=\'QuestionForm\'>");
  write("<textarea name=\'AnswerText\'cols=30 rows=10></textarea><br>");
  write("<input type=button value=\'提交答案\'onClick=\'parent.Win1.NextQ()\'>");
  write("</form></body></html>");
  close();
  }
}

<body onLoad="setTimeOut('PutQuestions()',1000)">
<h2 align=center>请您回答以下问题</h2></body></html>

以上代码都是在Win1页面写的。执行onload语句报错缺少对象,查了半天也没查出来,请问高手应该怎么改啊?

------解决方案--------------------
write("第",CurrentQuestion+1,"个问题: <font color=red >")中CurrentQuestion是什么。问题应该在这。如果是个变量,写法应该是write("第"+CurrentQuestion+"个问题:<fon..."),因为没办法在输出时候进行+1,所以是要事先CurrentQuestion = CurrentQuestion+1;
因为没有你的全部代码,只有有没有其他错误就不清楚

------解决方案--------------------
<html>
<head>
<title>
</title>
</head>
<script language="javascript">
function PutQuestions()

var CurrentQuestion=0;
open(); 
document.write("<html><head></head><body>"); 
document.write("第",CurrentQuestion+1,"个问题: <font color=red>"); 
document.write(Questions[CurrentQuestion]+" </font> <br>"); 
document.write(" <form name=\'QuestionForm\'>"); 
document.write(" <textarea name=\'AnswerText\' cols=30 rows=10 > </textarea> <br>"); 
document.write(" <input type=button value=\'提交答案\'

onClick=\'parent.Win1.NextQ()\'>"); 
document.write(" </form></body> </html>"); 
setTimeOut("PutQuestions()",10000);

</script>
<body onLoad="PutQuestions()"> 
<h2 align=center>请您回答以下问题 </h2> 
</body >
 </html >