我在试着计算OL的子元素
jQuery :
$(document).ready(function(){
$("#my_select").change(function(){
alert($("#ol3").children.length);
});});
HTML:
<ol id="ol1">
<li class="2">Location 1-1</li>
</ol>
<ol id="ol2">
<li class="15">Location 2-1</li>
<li class="20">Location 2-2</li>
</ol>
<ol id="ol3">
<li class="17">Location 3-1</li>
<li class="16">Location 3-2</li>
<li class="14">Location 3-3</li>
</ol>
不管有多少里,我总能得到第二名。
知道怎么回事吗..?
发布于 2010-05-31 02:11:28
试一试
$("#ol3").children().length \\ you missed () in children...
当您执行$("#ol3").children.length
时,它返回.children()
函数中的参数数.
试着提醒$("#ol3").children
,你会得到这个.
function (d,f){var e=c.map(this,b,d);eb.test(a)||(f=d);if(f&&typeof f==="string")e=c.filter(f,e);e=this.length>1?c.unique(e):e;if((this.length>1||gb.test(f))&&fb.test(a))e=e.reverse();return this.pushStack(e,a,R.call(arguments).join(","))}
其中d
和f
是两个论点..。这就是为什么你总是在你的代码中得到2当你警告。
发布于 2010-05-31 02:11:14
尝试children()
而不是children
。
要使用皮带和吊杆的方法,请尝试children('li')
。
发布于 2010-05-31 05:34:31
您还可以使用.size()代替.length()
这两种方法都能工作,尽管.length()应该更快。
https://stackoverflow.com/questions/2941057
复制相似问题