当前位置: 代码迷 >> JavaScript >> error: object expected,该如何处理
  详细解决方案

error: object expected,该如何处理

热度:963   发布时间:2012-02-16 21:30:36.0
error: object expected
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Strict//EN "
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> aaa </title>
<script   language= "text/javascript ">
var   intvalue=1;
var   timer2=null;
function   Startshow()
{                                                  
    var   liujincai   =   getElementById( "liujincai ");          
        liujincai.innerhtml=liujincai.innerhtml   +   "&nbsp; "   +   (intvalue   ++).tostring();
        timer2=window.settimeout( "startshow() ",2000);
}
function   stop()
{
        window.cleartimeout(timer2);
}
</script>
</head>
<body>
<div   id= "liujincai "> </div> //这一行报的错。。
<input   type= "button "   name= "start "   value= "start "   onclick= "Startshow(); ">
<input   type= "button "   name= "stop "   value= "stop "   onclick= "stop(); ">
</body>
</html>
不知道为什么,看了很久都没觉得有错

------解决方案--------------------
代码里面有太多的错误,所以才出错。

错误1:
<script language= "text/javascript "> ,修改为:
<script language= "javascript ">

错误2:
var liujincai = getElementById( "liujincai "); 修改为:
var liujincai = document.getElementById( "liujincai ");

错误3,错误4,错误5(三个大小写的错误):
liujincai.innerhtml=liujincai.innerhtml + "&nbsp; " + (intvalue ++).tostring();改为:
liujincai.innerHTML=liujincai.innerHTML + "&nbsp; " + (intvalue ++).toString();

错误6(大小写的错误):
timer2=window.settimeout( "startshow() ",2000);修改为:
timer2=window.setTimeout( "startshow() ",2000);


不看了,就看了这么多……
------解决方案--------------------
是的,错误得确很多,上面的还有一个地方需要改一下

liujincai.innerHTML=liujincai.innerHTML + "&nbsp; " + (intvalue ++).toString();
改成liujincai.innerHTML=liujincai.innerHTML + "&nbsp; " + (intvalue ++);
------解决方案--------------------
还有timer2=window.setTimeout( "startshow() ",2000);
改成timer2=window.setTimeout( "Startshow() ",2000);
  相关解决方案