为啥这一节我跟着老师写,不管怎么写,总是运行不了?
window.onload = function(){ var container = document.getElementsByClassName('container'); var photos = document.getElementsByClassName('photos'); // var buttons = document.getElementsByClassName('buttons').getElementsByTagName('span'); var buttons = document.getElementsByClassName('buttons'); var prev = document.getElementsByClassName('prev'); var next = document.getElementsByClassName('next'); function animate(offset){ photos.style.left = parseInt(photos.style.left) + offset +'px'; } next.onclick = function(){ animate(-600); } prev.onclick = function(){ animate(600); } }
我甚至都把ID全部换成了class,但还是不行。我注释的那一行运行的时候老是报错。。。