jQuery:.children()[index]不允许函数调用

Nic*_*ick 1 indexing jquery children function

为什么这不起作用......

$( '#父')的儿童()[3]的.html( '内容').

不起作用 TypeError:$("#parent").children()[3] .html不是函数.

什么时候这样做?

var x = $('#parent').children()[3] .className;

有用吗

在我现在捣碎的jsperf测试中找到了一个例子

谢谢.

Adi*_*dil 8

$("#parent").children()[3]给你javascript object not jQuery object和html没有在javascript中定义,但className存在于javascript中.用户] innerHTML获取html.Ø

Note: $("#parent").children()[3].html ,这里的html甚至没有在jQuery中定义你需要使用html()而不是像下面的例子中给出的那样,并使用eq来获取jQuery对象 $("#parent").children().eq(2).html()

现场演示

alert($("#parent").children()[2].innerHTML);
Run Code Online (Sandbox Code Playgroud)

要么

alert( $("#parent").children().eq(2).html());
Run Code Online (Sandbox Code Playgroud)