DMi*_*Min 4 html jquery children
我正在尝试计算OL的子元素
jQuery:
$(document).ready(function(){
$("#my_select").change(function(){
alert($("#ol3").children.length);
});});
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
我总是得到2号,不管有多少里面的人.
知道发生了什么......?
Rei*_*gel 12
尝试
$("#ol3").children().length \\ you missed () in children...
Run Code Online (Sandbox Code Playgroud)
当你这样做时$("#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(","))}
Run Code Online (Sandbox Code Playgroud)
其中d和f是两个参数...这就是为什么你总是在你的代码得到2,当你警惕..
| 归档时间: |
|
| 查看次数: |
17760 次 |
| 最近记录: |