这里有一个小故事...我想做一个for循环,使make的addenventlisteners,所以当我移动:hover/onmouseover它应该换成2种颜色。但我无法弄清楚如何获取关键字到功能redB ...javascript函数事件...从一个函数发送到另一个 - 也许很简单
但我不知道如果我的分辩方式...
$(document).ready(function() {
var i;
for (i = 0; i < 10; i++) {
document.getElementById("sek2" + i +).addEventListener("mouseover", Over(this));
document.getElementById("sek2" + i +).addEventListener("mouseout", Out(this));
}
});
function greyB(x) {
x.style.backgroundColor = "grey";
}
function redB(x) {
x.style.backgroundColor = "red";
}
'阅读进度( “鼠标悬停”,greyB)'和'阅读进度( “鼠标移开”,redB)' – Satpal
一些建议,使用[querySelectorAll ](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll)作为选择器,然后将sek2分配给页面上的所有10个元素。不需要使用ID来处理非常相似的元素。 – Neil
是的,但他也必须改变功能本身。 'x'将是事件,它们应该是'x.target.style.backgroundColor' – Ematipico