0
好的。所以我有一個這樣的列表(基本上) A)生產線a a)產品線 b)生產線b b)產品線 我希望列表展開和摺疊,因爲頁面不必要的大以容納高度。這裏是我的代碼Javascript-嵌套列表不會擴展
<script type="text/javascript">
function toggle(id) {
ul = "ul_" + id;
img = "img_" + id;
ulElement = document.getElementById(ul);
imgElement = document.getElementById(img);
if (ulElement){
if (ulElement.className == 'closed'){
ulElement.className = "open";
imgElement.src = "images/opened.gif";
}
else{
ulElement.className = "closed";
imgElement.src = "images/closed.gif";
}
}
}
</script>
的CSS
#portslist{
color:black;
border: 1px solid #babec9;
}
#portslist ul {
color:black;
font-size: 12px;
padding-left:3px;
}
#portslist ul li {
}
#portslist ul li ul {
padding: 5px 4px 4px;
font-size:9px;
}
#portslist ul li ul li{
color:black;
height:15px;
margin-left:10px;
}
.open
{display:block;}
.closed
{display:none;
}
li img {
vertical-align:middle;
cursor:pointer;
}
的HTML:
<ul class="open">
<li id="item1"><a onlick="toggle('item1');"><img src="images/closed.gif" alt="" id="img_item1" border="0"></a> Texas Instruments
<ul id="ul_item1" class="closed">
<li id="item1_1">RM4x DCAN</li>
</ul>
</li>
<li> Amtel
<ul class="closed">
<li>SAM7</li>
</ul>
</li>
<li>Freescale
<ul class="closed">
<li>HCS08</li>
<li>HCS12</li>
<li>HCS12X</li>
<li>MC68xxx</li>
<li>MCF5xxx</li>
<li>MPC5xxx</li>
<li>Kinetis Kxx</li>
</ul>
</li>
</ul>
謝謝大家這麼多的幫助提前。
非常感謝。我是否需要在腳本中包含該腳本? – michaelfward
沒關係。對不起,我在這裏睡了三個小時,我無法忍受沒有找到答案。一切順利,謝謝! – michaelfward