如果我们以list.style.left作为参照的话,切换的代码可以这样:
//按钮切换
for (var i = 0, length = buttons.length; i < length; i++) {
buttons[i].onclick = function (i) {
var index = this.getAttribute('index');
list.style.left = index * (-600) + 'px';
setButtonClass(parseInt(list.style.left));
}
}
总体的代码都会简单很多