我遇到了问题......这是交易。我有很多元素和一个按钮隐藏所有的,看起来像getElementById()打破循环
组别(例如ID =“1”)
- 一号线(例如那DIV ID =“1-1”级= “蓝色 ”)
- LINE2(例如那格,ID =“ 1-2" 类=” 蓝色 “)
- line3中(例如那格,ID =” 1 -3“class =”red“)
- line4(例如thats div,id =”1-4“c lass =“green”)
等等线有不同的类,这是一个很长的故事。事情是我需要隐藏“Category1”标题(div),如果没有可见的元素。没关系。 也是我需要在该类别中的任何行会再次出现,以显示它...
所以我有这个
(IDL =行类(联想庞大,包含蓝色,红色,绿色等),通过自定义功能getElementsByClassName方法()......这就是“秀行”功能
for (i=0;i<idl.length;i++)
{
idl[i].style.display = "block";
cla = idl[i].id;
if (cla[1]='-') {cla = cla[0];}
else {cla = cla[0] + cla[1];} //weird way to get Category id but works
//just cut off "-1" "-2" part of line IDs
// loop is doing it's job.
/* if (getElementById(cla) || getElementById(cla).style.display!="block") {
getElementById(cla).style.display = "block";
}
*/
// now here if I use 3 lines above it stops. 1st loop and that's it.
// even after getElementById("12345"), after getElementById(everything here)
// and nothing happening if i put alert anything after
有什么建议?
如果它“停止”意味着有错误。您应该始终在测试JavaScript时打开JavaScript控制台(或Firebug或其他调试工具),否则您将浪费很多时间。 – Pointy 2012-01-29 19:48:27
用jquery,它会很简单。 '$('#1')。children()。hide();' – 2012-01-29 19:48:39
另外,Id不应以数字开头。 – Johny 2012-01-29 19:50:32