适用于Firefox但不适用于其他浏览器。
function slideshowUp() {
num = num + 1
if (num == 4) {
num = 1
}
document.mypic.src = eval("img" + num + ".src")
document.jenn.lopez.value = eval("text" + num)
}
我们从Chrome获得的错误:
未捕获的TypeError:无法设置属性' src'未定义的ps.html:39 slideshowUp ps.html:39(匿名函数)
<script language="JavaScript" type="text/javascript">
var num=1
img1 = new Image ()
img1.src = "images/Lopez_Project_web.jpg"
img2 = new Image ()
img2.src = "images/Lopez_magazine_web.jpg"
img3 = new Image ()
img3.src = "images/collage_web.jpg"
text1 = "Mask of Flight"
text2 = "Training 101"
text3 = "Collage"
function slideshowUp()
{
num=num+1
if (num==4)
{num=1}
document.mypic.src=eval("img"+num+".src")
document.jenn.lopez.value=eval("text"+num)
}
function slideshowBack()
{
num=num-1
if (num==0)
{num=3}
document.mypic.src=eval("img"+num+".src")
document.jenn.lopez.value=eval("text"+num)
}
</script>
</header><br>
<div class="c1">
<a href="JavaScript:slideshowBack()"><img src="images/back.png" alt="Back" align="left"></a>
<a href="JavaScript:slideshowUp()"><img src="images/next.png" alt="Next" align="right"></a>
<img src="images/Lopez_Project_web.jpg" alt= "Mask of Flight" id="mypic">
<p>
<form name="jenn">
<input type="text" name="lopez" value="Mask of Flight">
</form>
这是我在Firefox中运行的代码,但不适用于IE或Chrome