本人JSP菜鸟,想写个动态图片网页。写出后却显示网页有错误,效果出不来,望各位大侠帮帮再下吧~~~~
下面 是代码(帮帮看下哪有错啊 )
<html>
<head>
<title></title>
<script language="JavaScript">
var number=0;
var timeOutID=null;
var picture=new Array(3);
for(var i=0;i<3;i++)
{
 picture[i]=new Image();
}function checkValid(s)
{
 var len=s.length;
 for(var i=0;i<len;i++)
{
 if(s.charAt(i)!="")

 return true;
}
}
return false;
}function loadNewPicture()
{
 picture[0].url="00.jpg";
 picture[1].url="01.jpg";
 picture[2].url="02.jpg";
}
function loadModifyPicture()
{
  if(checkValid(document.info.firstPicture.value))
 {
  picture[0].url=document.info.firstPicture.value;
 }
else
 {
 picture[0].url="00.jpg";
 }
 if(checkValid(document.info.secondPicture.value))
 {
 picture[1].url=document.info.secondPicture.value;
 }
 else
 {
 picture[1].url="01.jpg";
 }
 if(checkValid(document.info.thirdPicture.value))
 {
 picture[2].url=document.info.thirdPicture.value;
 }
 else
 {
 picture[2].url="02.jpg";
 }function setPicture(sort)
{
 var pictureURL="";
  if(sort=="first")
 {
  if(checkValid(document.info.firstPicture.value))
  {
  pictureURL=document.info.firstPicture.value;
   }
  else
  {
   pictureURL="00.jpg";
   }
 }
 else if(sort=="second")
 {
  if(checkValid(document.info.secondPicture.value))
  {
   pictureURL=document.info.secondPicture.value;
  }
  else
 {
  pictureURL="01.jpg";
  }
 }
 else if(sort=="third")
 {
  if(checkValid(document.info.thirdPicture.value))
 { 
  pictureURL=document.info.thirdPicture.value;
 }
  else
 {
  pictureURL="02.jpg";
  }
 }
 document.info.showPicture.src=pictureURL;
} function checkPlay()
{
  if(timeOutID!=null)
 {
   clearTimeout(timeOutID);
   timeOutID=null;
  }
} function playPicture()
{
 document.info.showPicture.src=picture[number].url;
 number=(number+1)%3;
 timeOutID=setTimeout("playPicture()",1500);
}
</script>
</head>
<body onLoad="loadNewPicture()">
<form name="info">
<h3>Example:image对象的应用</h3>
<img src="00.jpg" name="showPicture" border=10 hspace=15
 vspace=15 width=750 height=619>
<br>
<font size=2>重新设定第一幅图片:</font>
<input type="input" name="firstPicture" size=30>
<input type="button" name="setFirstPicture" value="设置为静态图片" onClick="checkPlay();setPicture('first')">
<br>
<font size=2>重新设定第二幅图片:</font>
<input type="input" name="secondPicture" size=30>
<input type="button" name="setSecondPicture" value="设置为静态图片" onClick="checkPlay();setPicture('second')">
<br>
<font size=2>重新设定第三幅图片:</font>
<input type="input" name="thirdPicture" size=30>
<input type="button" name="setThirdPicture" value="设置为静态图片" onClick="checkPlay();setPicture('third')">
<br><br>&nbsp&nbsp&nbsp
<input type="button" name="play" value="动态展示图片" onClick="if(timeOutID==null){loadModifyPictur();
playPicture()}">
&nbsp&nbsp&nbsp
<input type="button" name="play" value="停止展示图片" onClick="checkPlay();">
</form>
</body>
</html>

解决方案 »

  1.   

    loadModifyPicture函数缺少括号
    给个小小的建议,编写代码的时候要规范,尤其对于初学者,可以避免不必要的错误
      

  2.   

    <body onLoad="loadNewPicture()"> 
    <form name="info"> 
    <h3>Example:image对象的应用 </h3> 
    <img src="00.jpg" name="showPicture" border=10 hspace=15 
    vspace=15 width=750 height=619> 
    <br> 
    <font size=2>重新设定第一幅图片: </font> 
    <input type="input" name="firstPicture" size=30> 
    <input type="button" name="setFirstPicture" value="设置为静态图片" onClick="checkPlay();setPicture('first')"> 
    <br> 
    <font size=2>重新设定第二幅图片: </font> 
    <input type="input" name="secondPicture" size=30> 
    <input type="button" name="setSecondPicture" value="设置为静态图片" onClick="checkPlay();setPicture('second')"> 
    <br> 
    <font size=2>重新设定第三幅图片: </font> 
    <input type="input" name="thirdPicture" size=30> 
    <input type="button" name="setThirdPicture" value="设置为静态图片" onClick="checkPlay();setPicture('third')"> 
    <br> <br>&nbsp&nbsp&nbsp 
    <input type="button" name="play" value="动态展示图片" onClick="if(timeOutID==null){loadModifyPictur(); 
    playPicture()}"> 
    &nbsp&nbsp&nbsp 
    <input type="button" name="play" value="停止展示图片" onClick="checkPlay();"> 
    </form> 
    </body> 
    </html>调用js的方法名写错了.