DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> jQuery實現簡單二級下拉菜單
jQuery實現簡單二級下拉菜單
編輯:JavaScript綜合知識     

 html代碼

1 2 3 4 5 6 7 8 <div class="UpLayer"> <dl> <dt> <a href="javascript:void(0)"></a></dt> <dd> <a href="http://www.demo.com/js/">特效</a> <a href="http://www.demo.com/Tutorials/">教程</a> <a href="http://www.demo.com/zy/">資源</a> <a href="http://www.demo.com/mb/">模板</a> <a href="http://www.demo.com/news/">資訊</a></dd> </dl> </div>

js代碼

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <script type="text/javascript"> // 【經典】彈出層菜單 $(document).ready(function(){ var objStr = ".UpLayer"; $(objStr).each(function(i){ $(this).click(function(){ $($(objStr+" dd")[i]).show(); $($(objStr+" dt")[i]).addClass("UpLayer02"); }); $(this).hover(function(){},function(){ $($(objStr+" dd")[i]).hide(); $($(objStr+" dt")[i]).removeClass("UpLayer02"); }); }); }); </script>

css代碼

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 body,h1,h2,h3,h4,h5,h6,p,ol,ul,li,dl,dt,dd{padding:0;margin:0;} li{list-style:none;} img{border:none;} u{text-decoration:none;} em{font-style:normal;} a{color:#424242;text-decoration:none;outline:none;blr:expression(this.onFocus=this.blur());} body{font-size:12px;font-family: Arial,Verdana, Helvetica, sans-serif; word-break:break-all;} .box{margin:0 auto;text-align:left;width:920px;} .clear{clear:both;} /* 【經典】彈出層菜單 */ .UpLayer{ margin:100px;} .UpLayer dl dt{width:50px;position:absolute; z-index:3;padding:0 5px;line-height:20px;} .UpLayer02{border:#ccc 1px solid; border-bottom:none;background:#f1f1f1; margin:-1px 0 0 -1px;} .UpLayer dl dd{ width:80px;position:absolute;z-index:2;border:#ccc 1px solid;padding:5px; line-height:20px; background:#f1f1f1; display:none; margin:19px 0 0 -1px;} .UpLayer dl dd a{ display:block;border-bottom:#ccc 1px dashed;}

最好不要忘記插入jQuery js文件,最好下載最新的。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved