html li标签使用javascript隐藏 [英] html li tags hide using javascript
本文介绍了html li标签使用javascript隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您能在此标记上帮助我如何使用javascript隐藏第二个li标签吗?
li标签是动态填充的项目,如下例所示
can you help me on this markup on how to hide 2nd li tag using javascript?
the li tags is dynamic populated item like the example below
<ul id="mUl">
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
</ul>
在此先感谢
thanks in advance
推荐答案
使用jquery.
use jquery.
("ui li")[1] .css("display","none");
否则,
document.getElementById("mUl").children [1] .style.display ="none";
("ui li")[1].css("display","none");
otherwise,
document.getElementById("mUl").children[1].style.display="none";
< html>
< head>
< script>
函数invisible()
{
document.getElementById("mUl").children [2] .style.display ="none";
}
</script>
</head>
< body onload ="invisible()">
< ul id ="mUl">
< li> a</li>
< li&b; b</li>
< li> c</li>
< li> d</li>
< li&e;/li>
< li> f</li>
</ul>
</body>
</html>
//将上面的代码另存为".html"并在浏览器上运行.您会发现您的第二个li标签被隐藏了.
<html>
<head>
<script>
function invisible()
{
document.getElementById("mUl").children[2].style.display="none";
}
</script>
</head>
<body onload="invisible()">
<ul id="mUl">
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
</ul>
</body>
</html>
//save the above code as ".html" and run at browser. you ll find ur 2nd li tag hidden.
这篇关于html li标签使用javascript隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文