首页 > 代码库 > 2_展开菜单

2_展开菜单

HTMl代码:

1 <div><p id="btn">输入法</p>2 <ul id="list" style="display:block;">3 <li>搜狗输入法</li>4 <li>智能全拼输入法</li>5 <li>腾讯输入法</li>6 <li>日文输入法</li>7 </ul></div>8 </body>

CSS代码:

1 *{ margin:0; padding:0;}2 div{ width:140px; overflow:hidden; font-size:14px; }3 #btn{ display:block; text-align:center; background:#006; color:#fff; padding:4px 0;}4 #list{ display:block;}5 #list li{ display:block; background:#09F; list-style:none; padding:6px 0 6px 10px; font-size:14px;}

JS代码:

 1 window.onload=function () 2 { 3     var obtn=document.getElementById(‘btn‘); 4     var olist=document.getElementById(‘list‘);     5     obtn.onclick=function(){ 6         if( olist.style.display==‘block‘){   //注意这里是等于,  不“=”! 7             olist.style.display=‘none‘; 8             } 9         else{ olist.style.display=‘block‘;}10         }11 }

 

2_展开菜单