為啥這一節我跟著老師寫,不管怎么寫,總是運行不了?
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,但還是不行。我注釋的那一行運行的時候老是報錯。。。
2016-07-20
window.onload?=?function(){ var?container?=?document.getElementsByClassName('container')[0]; var?photos?=?document.getElementsByClassName('photos')[0]; // var?buttons?=?document.getElementsByClassName('buttons').getElementsByTagName('span')[0]; var?buttons?=?document.getElementsByClassName('buttons')[0]; var?prev?=?document.getElementsByClassName('prev')[0]; var?next?=?document.getElementsByClassName('next')[0]; function?animate(offset){ photos.style.left?=?parseInt(photos.style.left)?+?offset?+'px'; } next.onclick?=?function(){ animate(-600); } prev.onclick?=?function(){ animate(600); } }寫成這樣可以實現圖片的切換,但是獲取的是buttons元素而不是buttons下的span元素,如果把注釋的那一行換成不注釋的話,就不能運行了,這是怎么回事,我前兩天用的時候,還可以的???