有必要实现以下功能 - 通过onclick按钮(about-btn),应该将一个类(about-item-img-active)添加到随机元素(about-item-img):
window.onload = function() {
var btn = document.querySelectorAll('.about-btn');
var div = document.querySelectorAll('.about-item-img');
var rand = mtRand(0, div.length - 1);
for (var i = 0; i < btn.length; i++) {
btn[i].onclick = activeItem.call(div[rand]);
}
function activeItem() {
this.classList.toggle('about-item-img-active');
}
}
function mtRand(min, max) {
return Math.floor(Math.random() * (max - min + 1));
}
帮助更正或更改代码。