- HTML code
<ul id="nav"> <li><img src="A.jpg" alt="" /></li> <li><img src="B.jpg" alt="" /></li> <li><img src="C.jpg" alt="" /></li> <li><img src="D.jpg" alt="" /></li> </ul> <div id="place"><img src="A.jpg" alt="sss" id="images"/></div>
- JScript code
function test() { var list = document.getElementById("nav"); var img = list.getElementsByTagName("img"); for(var i = 0;i<img.length;i++) { img[i].onclick = function() { setSource(this); } } } function setSource(which) { var source = which.getAttribute("src"); var place = document.getElementById("place"); place.setAttribute("src",source); } window.onload = test;
四个缩略图,点击任何一个会在下方显示大图 可是点击怎么没反应呢??
------解决方案--------------------
var place = document.getElementById("place");
你这怎么设置层的SRC
var place = document.getElementById("images");
------解决方案--------------------
- JScript code
function setSource(which) { document.getElementById('place').getElementsByTagName('img')[0].src = which.src; }
------解决方案--------------------
var place = document.getElementById("place");
place.setAttribute("src",source);
低级错误,你把src赋给div了。