<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>圖片展示</title> <style type="text/css"> p { width: 500px; height: 500px; } img { max-width: 100%;? border: 2px solid teal; cursor: pointer; } </style></head><body><h1>圖片展示</h1><p><img src="1.jpg" id="slideimage" name="image_0" alt="home"></p><script type="text/javascript"> var images=['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg']; function nextImage(){ var img = document.getElementById("slideimage");//這里的split不是表示分隔符,imgname[1]為什么會返回一個數字,img.name 也不是一個數字啊,他前面還有image var imgname = img.name.split("_"); var index = imgname[1]; if (index == images.length-1) { index = 0; }else { index++; } img.src = images[index]; img.name = "image_"+index; console.log(index); } document.getElementById("slideimage").setAttribute("onclick","nextImage()");</script></body></html>
求問:見程序,var index = imgname[1];為什么這條語句會返回一個數字?
aladdinx
2016-04-29 16:51:11