亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為啥這一節我跟著老師寫,不管怎么寫,總是運行不了?

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,但還是不行。我注釋的那一行運行的時候老是報錯。。。

正在回答

1 回答

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元素,如果把注釋的那一行換成不注釋的話,就不能運行了,這是怎么回事,我前兩天用的時候,還可以的???

1 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為啥這一節我跟著老師寫,不管怎么寫,總是運行不了?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號