这段代码对我很有用,但我需要侦听器中的两个变量是代表您单击的项目的动态数字。当然,现在它们被硬编码为“7”,但我所需要的只是让它们动态化。
var items = document.getElementsByClassName('largeItems');
for (var i = 0; i < items.length; i++) {
items[i].addEventListener('click', function() {
var itemWays = 7;
var currentItem = 7;
document.getElementById('display').src = detailsImage[itemWays];
}, false);
}
我想我想要这样的东西:
var itemWays = this.items[i]; //this.itemIndex that was clicked
var currentItem = this.items[i]; //this.itemIndex that was clicked
干杯,