日期:2014-05-16  浏览次数:20309 次

怎么样得到<UL>下面有多少具<li>
怎么样得到<UL>下面有多少具<li>??

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>    
        <style>
        </style>        
    </head>
    <body>
        <ul id="test">
            <li>1-1</li>
            <li>1-1</li>
            <li>1-1</li>
            <li>1-1</li>
            <li>1-1</li>
            <li>1-1</li>
        </ul>
        <script>
            function $(el){
                return typeof el == 'string' ? document.getElementById(el) : el;
            }
            function $t(name, cot){
                cot = cot || document;
                return cot.getElementsByTagName(name);
            }
            alert( $t('li', $('test')).length )
        </script>
    </body>
</html>

------解决方案--------------------
UL有什么标识 ID? NAME? CLASS?

JQuery:

$("ul").find("li").length;
------解决方案--------------------
探讨

UL有什么标识 ID? NAME? CLASS?

JQuery:

$("ul").find("li").length;

------解决方案--------------------
document.getElementById("ul_id").getElementsByTagName("li").length;//ul_id是你自己ul的id,后面是li标签,不用改。
------解决方案--------------------
$('ul li').length
------解决方案--------------------
探讨
$('ul li').length

------解决方案--------------------
探讨

document.getElementById("ul_id").getElementsByTagName("li").length;//ul_id是你自己ul的id,后面是li标签,不用改。

------解决方案--------------------
document.write(document.getElementsByTagName("ul")[0].getElementsByTagName("li").length);

------解决方案--------------------
document.getElementsByTagName("ul")[0].getElementsByTagName("li").length
------解决方案--------------------
探讨

不是,是这各形式。

------解决方案--------------------
alert($("ul li").length);
------解决方案--------------------
探讨

引用:

不是,是这各形式。

document.getElementById("sele").getElementsByTagName("li").length