Title
window.onload=function() {
var abtn = document.getElementsByTagName("input");
var op = document.getElementById("inner");
var astyle = ["width", "height", "backgroundColor", "display", "display"];
var avalue = ["200px", "200px", "red", "none", "block"]
function changeStyle(obj, attr, value) {
obj.style[attr] = value;
};
/* for (var i = 0; i < abtn.length; i++) {
abtn[i].onclick = (function (i) {
console.log(i);//检查了下i的值都能依次取到。
i== abtn.length - 1 && (op.style.cssText = "");
changeStyle(op, astyle[i], avalue[i]);
})(i)
}*/
}
模仿大神(http://fgm.cc/learn/lesson1/01.html)的代码做练习,结果我抄都没抄成功,请问是什么原因呢?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为你给btn赋的事件处理函数是函数的返回值,而你的返回值是空值,也就是说事件处理函数都是空的,自然就没有效果。