使用在循环内分配的onclick事件,但问题已经发生
matej.prototype.animacia = function () {
var tab = document.getElementById("table");
var x = tab.querySelectorAll(".lol td");
var kontrola=true;
for (var i = 0; i < x.length; i++) {
x[i].onclick = function (e) {
e = e ? e : window.event;
var decko = e.target.querySelector(".bodky");
var bastard = e.target.querySelector(".hidden");
var hore = 0;
kontrola=false;
var id = function () {
decko.style.opacity = 1 - hore;
hore += 0.05;
if (hore < 1) {
setTimeout(function () {
id();
}, 10);
} else {
decko.style.display = "none";
decko.style.opacity = 0;
(function (e) {
e = e ? e : window.event;
var dole = 0;
var di = function () {
bastard.style.display = "inline";
bastard.style.opacity = 0 + dole;
dole += 0.05;
if (dole < 1) {
setTimeout(function () {
di();
}, 100);
} else {
bastard.style.opacity = 1;
}
};
di();
})();
}
};
id();
}
};}
它按预期“工作”,但我必须按顺序点击“TD”元素(从最后一个到第一个)否则会抛出错误。为什么会这样? 工作演示http://jsfiddle.net/Trolstover/qxd32hkk/5/