尝试使用JavaScript将图像源从"images/small/"更改为"images/medium/"
我已尝试以下代码,但由于某些原因单击事件未被捕获,请感谢您提供的任何帮助。
Javascript
var thumbs = document.getElementById("thumbnails");
thumbs.addEventListener("click", function (i) {
if (i.target.nodeName.toLowerCase() == "img") {
// get image filename of clicked thumbnail
var clickedImageSource = i.target.src;
// replace the folder name of the image
var newSrc = clickedImageSource.replace("small","medium");
}
});
HTML
<div id="thumbnails">
<img src="images/small/Home.jpg" title="Home" />
<img src="images/small/Office.jpg" title="Office" />
<img src="images/small/Park.jpg" title="Park" />
<img src="images/small/Hills.jpg" title="Hills" />
<img src="images/small/HaveEyes.jpg" title="HaveEyes" />
</div>