課程
/前端開發(fā)
/JavaScript
/Tab選項(xiàng)卡切換效果
這段還是不太理解。。。
2015-01-04
源自:Tab選項(xiàng)卡切換效果 2-1
正在回答
我有個(gè)類似的代碼,發(fā)現(xiàn)和你不同的“this.className='';???”;我的是“titles[j].className="";”
出問(wèn)題了,沒反應(yīng)啊,求解
unction $(id){?? ?return typeof id==='string'?document.getElementById(id):id;?? ?}window.onload=function(){?? ?//獲取鼠標(biāo)滑過(guò)或者是點(diǎn)擊的標(biāo)簽和要切換的內(nèi)容元素?? ?var titles=$('notice-tit').getElementsByTagName('li');?? ?divs=$('notice-con').getElementsByTagName('div');?? ?if(titles.length!=divs.length)?? ??? ?return;?? ?//遍歷titles下所有的li?? ?for(var i=0; i<titles.length;i++){?? ??? ?titles[i].id=i;?? ??? ??? ??? ?titles[i].onmouseover=function(){?? ??? ??? ?//清除所有l(wèi)i上的class?? ??? ??? ?for(var j=0; j<titles.length;j++){?? ??? ??? ?this.className='';?? ??? ??? ??? ?divs[j].style.display='none';?? ??? ??? ?};?? ??? ??? ?//設(shè)置當(dāng)前為高亮顯示?? ??? ??? ?this.className='select';?? ??? ??? ?//鼠標(biāo)滑過(guò)顯示內(nèi)容?? ??? ??? ?divs[this.id].style.display='block';?? ??? ?};?? ??? ??? ?};?? ?};
這個(gè) 函數(shù)的作用就是之后用到id選擇器可以簡(jiǎn)寫,至于判斷的意義就是傳入的參數(shù)為字符串就返回
document.getElementById(id),其他的就返回參數(shù)本身,這個(gè)只是一個(gè)獲取頁(yè)面dom元素的一個(gè)簡(jiǎn)陋版本的函數(shù),還不夠完善。
orangecat
hnull 回復(fù) orangecat
這樣判斷有什么意義嗎?
舉報(bào)
本課程詳細(xì)介紹網(wǎng)頁(yè)頁(yè)面中最流行常用的tab切換效果
7 回答function $(id){ return typeof id==='string'?document.getElementById(id):id; }
1 回答function $(id){ return typeof id==="string"?document.getElementById("id"):id}
2 回答function $(id){return typeof id==='string'?document.getElementsById(id):id;},
3 回答function $(id) { return typeof id==='string' ? document.getElementById(id):id;這行代碼有什么用???
3 回答請(qǐng)問(wèn)同學(xué)這是什么意思??function $(id){ return typeof id==='string'?document.getElementsById(id):id; }是什么意思
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-01-05
我有個(gè)類似的代碼,發(fā)現(xiàn)和你不同的“this.className='';???”;我的是“titles[j].className="";”
2016-11-07
出問(wèn)題了,沒反應(yīng)啊,求解
unction $(id){
?? ?return typeof id==='string'?document.getElementById(id):id;?? ?
}
window.onload=function(){
?? ?//獲取鼠標(biāo)滑過(guò)或者是點(diǎn)擊的標(biāo)簽和要切換的內(nèi)容元素
?? ?var titles=$('notice-tit').getElementsByTagName('li');
?? ?divs=$('notice-con').getElementsByTagName('div');
?? ?if(titles.length!=divs.length)
?? ??? ?return;
?? ?//遍歷titles下所有的li
?? ?for(var i=0; i<titles.length;i++){
?? ??? ?titles[i].id=i;
?? ??? ?
?? ??? ?titles[i].onmouseover=function(){
?? ??? ??? ?//清除所有l(wèi)i上的class
?? ??? ??? ?for(var j=0; j<titles.length;j++){
?? ??? ??? ?this.className='';?? ?
?? ??? ??? ?divs[j].style.display='none';
?? ??? ??? ?};
?? ??? ??? ?//設(shè)置當(dāng)前為高亮顯示
?? ??? ??? ?this.className='select';
?? ??? ??? ?//鼠標(biāo)滑過(guò)顯示內(nèi)容
?? ??? ??? ?divs[this.id].style.display='block';
?? ??? ?};?? ??? ?
?? ?};
?? ?
};
2015-02-05
這個(gè) 函數(shù)的作用就是之后用到id選擇器可以簡(jiǎn)寫,至于判斷的意義就是傳入的參數(shù)為字符串就返回
document.getElementById(id),其他的就返回參數(shù)本身,這個(gè)只是一個(gè)獲取頁(yè)面dom元素的一個(gè)簡(jiǎn)陋版本的函數(shù),還不夠完善。
2015-01-04
這樣判斷有什么意義嗎?