課程
/前端開發
/JavaScript
/JavaScript進階篇
弄成代碼快照 方便看
2014-11-28
源自:JavaScript進階篇 10-1
正在回答
1.51行多了一個“<br>”
2.63,64行的this看作用域知道指的是window對象,其屬性className和index都是undefined。
正確的應該把
this.className="on";
odiv[this.index].className="";
這兩行放在第一個for循環內,最終為
<script type="text/javascript">
? ? ? ? window.onload = function(){
? ? ? ? ? ?var otabl = document.getElementById("tabl");? ? ??
? ? ? ?var oli = document.getElementsByTagName("li");
? ? ? ?var odiv = otabl.getElementsByTagName("div");
? ? ? ? for(var i=0;i<oli.length;i++){
? ? ? ? ? ?oli[i].index = i;
? ? ? ? ? ?oli[i].onclick = function() {
? ? ? ? ? ? ? ? ?for(var n=0;n<oli.length;n++){
? ? ? ? ? ? ? ? ?oli[n].className="";
? ? ? ? ? ? ? ? ? ? ?odiv[n].className="hide"
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?this.className="on";
? ? ? ? ? ? ? odiv[this.index].className="";
? ? ? ? ? }? ? ? ?
? ? ? ? }
? ? ? }
?? ? </script>
希望對你能有所幫助^_^
this.className="on"; odiv[this.index].className="";//顯示下一個div
這兩行要寫在onclick函數里面,否則在外面this是誰都不知道
舉報
本課程從如何插入JS代碼開始,帶您進入網頁動態交互世界
2 回答我這為什么javascript效果出不來 求大神幫我看看 , 找了一上午了 不知道問題出哪了······
5 回答不知道為什么輸出不了week?大神來幫我看看
1 回答求大神幫我看看代碼沒有效果, 哪里出問題了,找了半天!多謝了
4 回答求大神們幫我看看代碼哪里出錯了?為什么運行不出結果?
4 回答求大神幫我看看哪里錯了 實在不知道了
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2014-11-28
1.51行多了一個“<br>”
2.63,64行的this看作用域知道指的是window對象,其屬性className和index都是undefined。
正確的應該把
this.className="on";
odiv[this.index].className="";
這兩行放在第一個for循環內,最終為
<script type="text/javascript">
? ? ? ? window.onload = function(){
? ? ? ? ? ?var otabl = document.getElementById("tabl");? ? ??
? ? ? ?var oli = document.getElementsByTagName("li");
? ? ? ?var odiv = otabl.getElementsByTagName("div");
? ? ? ? for(var i=0;i<oli.length;i++){
? ? ? ? ? ?oli[i].index = i;
? ? ? ? ? ?oli[i].onclick = function() {
? ? ? ? ? ? ? ? ?for(var n=0;n<oli.length;n++){
? ? ? ? ? ? ? ? ?oli[n].className="";
? ? ? ? ? ? ? ? ? ? ?odiv[n].className="hide"
? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?this.className="on";
? ? ? ? ? ? ? odiv[this.index].className="";
? ? ? ? ? }? ? ? ?
? ? ? ? }
? ? ? }
?? ? </script>
希望對你能有所幫助^_^
2014-12-16
這兩行要寫在onclick函數里面,否則在外面this是誰都不知道