您现在的位置是:首页 > 电脑技术查询 > web开发

如何样得到<UL>下面有多少具<li>

编辑:chaxungu时间:2022-10-02 23:15:13分类:web开发

怎么样得到<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