用純JS實(shí)現(xiàn)二級(jí)菜單效果
本文實(shí)例為大家分享了JS實(shí)現(xiàn)二級(jí)菜單效果的具體代碼,供大家參考,具體內(nèi)容如下
js點(diǎn)擊出現(xiàn)二級(jí)菜單,點(diǎn)擊二級(jí)菜單主菜單換成二級(jí)菜單
點(diǎn)擊出現(xiàn)二級(jí)菜單
<style>*{margin:0px auto;padding:0px;} .yiji{width:200px;height:40px;background-color:red;color:#fff;text-align:center;line-height:40px;hvertical-align:middle;border:1px solid #FFF;} .erji1{width:200px;height:40px;background-color:#F63;color:#fff;text-align:center;line-height:40px;vertical-align:middle;border:1px solid #FFF;} #erji2{display:none;} #erji3{display:none;} #erji4{display:none;} </style> </head> <body><div onclick='Show(’erji2’)'>首頁(yè)</div><div id='erji2'> <div class='erji1'>1</div> <div class='erji1'>1</div> <div class='erji1'>1</div> </div> <div onclick='Show(’erji3’)'>人才</div><div id='erji3'> <div class='erji1'>1</div> <div class='erji1'>1</div> <div class='erji1'>1</div> </div> <div onclick='Show(’erji4’)'>市場(chǎng)</div><div id='erji4'> <div class='erji1'>1</div> <div class='erji1'>1</div> <div class='erji1'>1</div></div> </body> <script type='text/javascript'>function Show(a){ var a = document.getElementById(a); if(a.style.display == 'block') {a.style.display = 'none'; } else {a.style.display = 'block'; }} </script>

#caidan{width:200px;height:40px;border:1px solid #999;text-align:center;line-height:40px;vertical-align:middle;} .list{ width:200px; height:40px; border:1px solid #999; border-top-width:0px; text-align:center; line-height:40px; vertical-align:middle; display:none; } #caidan,.list:hover{ cursor:pointer; } .list:hover{ background-color:#63F;}
<div style='width:200px; height:400px;'> <div onclick='Show()'>中國(guó)</div> <div onclick='Xuan(this)'>山東</div> <div onclick='Xuan(this)'>濟(jì)南</div> <div onclick='Xuan(this)'>濟(jì)寧</div> <div onclick='Xuan(this)'>威海</div> <div onclick='Xuan(this)'>淄博</div></div>
function Show(){ var list = document.getElementsByClassName('list'); //顯示列表 for(var i=0;i<list.length;i++) {list[i].style.display = 'block'; } } function Xuan(a){ var c = document.getElementById('caidan'); c.innerHTML = a.innerHTML; var list = document.getElementsByClassName('list'); //顯示列表 for(var i=0;i<list.length;i++) {list[i].style.display = 'none'; } }



以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Java進(jìn)行Appium自動(dòng)化測(cè)試的實(shí)現(xiàn)2. 詳細(xì)總結(jié)Java for循環(huán)的那些坑3. php中PHPUnit框架實(shí)例用法4. python對(duì)批量WAV音頻進(jìn)行等長(zhǎng)分割的方法實(shí)現(xiàn)5. 新手學(xué)python應(yīng)該下哪個(gè)版本6. jsp文件下載功能實(shí)現(xiàn)代碼7. uni-app結(jié)合PHP實(shí)現(xiàn)單用戶登陸demo及解析8. 如何利用Python matplotlib繪制雷達(dá)圖9. ajax實(shí)現(xiàn)頁(yè)面的局部加載10. PHP安全-過濾輸入

網(wǎng)公網(wǎng)安備