显示和隐藏订单列表

时间:2010-10-05 15:17:59

标签: html css dhtml javascript

String +

如果用户点击+号,我想显示一些oder列表

然后是字符串 -

如果用户点击 - 我要隐藏订单列表的标志

如何使用javascript实现此功能,而不是使用ajax,jquery

2 个答案:

答案 0 :(得分: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";
}
}

此方法可用于任何您想要显示/隐藏的内容。显然,你可以调用函数和变量,这是有意义的......

答案 1 :(得分: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 ....我刚刚完成了无序的粗略实施....