本人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>   
<input type="button" name="play" value="动态展示图片" onClick="if(timeOutID==null){loadModifyPictur();
playPicture()}">
   
<input type="button" name="play" value="停止展示图片" onClick="checkPlay();">
</form>
</body>
</html>
下面 是代码(帮帮看下哪有错啊 )
<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>   
<input type="button" name="play" value="动态展示图片" onClick="if(timeOutID==null){loadModifyPictur();
playPicture()}">
   
<input type="button" name="play" value="停止展示图片" onClick="checkPlay();">
</form>
</body>
</html>
解决方案 »
- extjs3怎么动态的给对象添加属性
- Node.JS
- 如何得到页面显示的图片的属性如大小,尺寸大小等。
- 请问这段代码有什么作用?
- jqGrid 的 ajaxSelectOptions 怎么使用?
- 急求:JavaScript如何将file上传到指定文件下,谢谢
- Javascript在IE与FireFox中的兼容性问题求教高手
- JS的修改 请帮忙
- 本人对Javascrip一窍不通,希望各位朋友能提供一个实现简单四则运算,并能统计成绩的源代码。都是老师惹的麻烦啊!
- easyui tabs 在ie8上面多个tab显示在一个tab下面
- 怎样控制div层内的文字
- Firefox中的onblur事件没有正常响应
给个小小的建议,编写代码的时候要规范,尤其对于初学者,可以避免不必要的错误
<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>   
<input type="button" name="play" value="动态展示图片" onClick="if(timeOutID==null){loadModifyPictur();
playPicture()}">
   
<input type="button" name="play" value="停止展示图片" onClick="checkPlay();">
</form>
</body>
</html>调用js的方法名写错了.