超簡單的js網站後臺管理功能摺疊選單程式碼
阿新 • • 發佈:2019-02-15
<style type="text/css">
*{margin:0;padding:0;}#nav{width:200px;margin:50px;}
#nav h3{cursor:pointer;line-height:30px;height:30px;background-color:#000000;color:#fff;}
#nav a{display:block;line-height:24px;color:#666666;}
#nav a:hover{background-color:#eee;color:#000;}
#nav div{display:none;border:1px solid #000;border-top:none;}
</style>
<script type="text/javascript">
function $(id){return document.getElementById(id)}
window.onload = function(){
$("nav").onclick = function(e){
var src = e?e.target:event.srcElement;
if(src.tagName == "H3"){
var next = src.nextElementSibling || src.nextSibling;
next.style.display = (next.style.display =="block")?"none":"block";
}
}
}
</script>
<div id="nav">
<h3>建站服務</h3>
<div>
<a href="#">留言本</a>
<a href="#">播放器</a>
<a href="#">計數器</a>
</div>
<h3>站長工具</h3>
<div>
<a href="#">ALEXA查詢</a>
<a href="#">PageRank查詢</a>
<a href="#">收錄查詢</a>
</div>
</div>
</td>
</tr>
</table>