2010-10-05 63 views
0

字符串+显示和隐藏顺序列表

如果用户点击+号,我想展示一些奥德列表

此后字符串 -

如果用户点击 - 号我想隐藏秩序名单

如何使用JavaScript达致这,不使用AJAX,jQuery的

回答

1

你将不得不为有序列表创建一个id,例如,

<ol id="superId"> 


</ol> 

然后于JavaScript

function displayOL(enabled) { 
    if (enabled) { 
    document.getElementById("superId").style.display = "none"; 
    document.getElementById("minus").style.display = "block"; 
    document.getElementById("plus").style.display = "none"; 
    } else { 
    document.getElementById("superId").style.display = "block" 
    document.getElementById("minus").style.display = "none"; 
    document.getElementById("plus").style.display = "show"; 
    } 
} 

然后anchor标签

<a href="#" onclick="displayOL(true)" id="plus">+</a> 

<a href="#" onclick="displayOL(false)" id="minus">-</a> 

PS ....我只是做了一个粗略的实施没有订单....

+0

我建议通过清除显示来显示元素,而不是将其设置为'block':'.style.display ='''。这样你就不会改变元素的内联/块形式 – Tomas 2010-10-07 09:44:57

1

尝试这样做,它连接到您的任何活动,即的onclick,的onmouseover,等等:

function toggleList(elem){ 
var theList = document.getElementById(elem); 

if(theList.style.display == "none"){ 
    theList.style.display == "block"; 
} 
else{ 
    theList.style.display == "none"; 
} 
} 

此方法可用于任何要显示/隐藏的内容。很明显,你可以调用函数和变量,你喜欢的任何有意义的东西...