@Cheeso's answer is a good pure-JS solution.
(@Cheeso的答案是一个很好的纯JS解决方案。)
But, if you're using jQuery, the process can be made simpler.(但是,如果您使用的是jQuery,则可以简化此过程。)
jQuery('div#000').children('ul').length;
The above code will return the number of child ul
elements of the div#000
.
(上面的代码将返回div#000
的子ul
元素的数量。)
To update the count when you add elements dynamically, you will have to create a function and call it to update the number whenever a change occurs:
(要在动态添加元素时更新计数,您将必须创建一个函数并在发生更改时调用它以更新数字:)
function countUls() {jQuery('div#000').children('ul').length;}
Bind that to an event so that it will be called when you want to update the number.
(将该事件绑定到事件,以便在您要更新号码时将其调用。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…