未捕获的TypeError:children [i] .children不是函数 [英] Uncaught TypeError: children[i].children is not a function
问题描述
我有一个函数,可以从列表"my_dynamic_list"中获取所有名称为"children-li"的li元素. 每个li元素都有三个复选框,分别是object_ck_bx,write_ck_bx,view_ck_bx,我需要获取该复选框的值,但是却得到"children is a function",为什么代码可以访问li标记名却不能访问li孩子们?
I have a function that gets the all the li elements with the name "children-li" from a list "my_dynamic_list". each li element has three checkboxes of the names object_ck_bx, write_ck_bx, view_ck_bx, I need to get the values of that checksboxes, but I get "children is not a function", why the code can access to li tag name but can not access li children?
function getTreeData() {
// Get All Li elements thats contains the checkboxes form the type object,read,write
var children = $('#my_dynamic_list').children().find('li[name=children-li]');
var extracted_data = [];
for (i = 0; i < children.length ; i++) {
alert(children[i].tagName); //this gives li
if (children[i].children().find('input[name=object_ck_bx]').checked == true) { // This Line gives Uncaught TypeError: children[i].children is not a function
var profile_code = children[i].children().find('input[name=object_ck_bx]').id;
var view = children[i].children().find('input[name=view_ck_bx]').checked;
var write = children[i].children().find('input[name=write_ck_bx]').checked;
alert('profile_code' + profile_code);
var item = [];
item = { Id: profile_code, read: view, write: write };
extracted_data.push(item);
}
}
// alert(extracted_data);
return extracted_data;
}
HTML代码:
浏览器中的li属性看起来像
The li properties in the browser looks like
推荐答案
首次调用.children()
时,您将获得HTMLElement
对象的简单数组.您尝试调用的方法.children()
是jQuery集合的方法.因此,为了从普通的HTMLElement
中创建一个jQuery对象,您会得到从children[i]
返回的结果,将其包装到jQuery构造函数中,如下所示:
When you call .children()
for the first time, you get back a plain array of HTMLElement
objects. The method .children()
you are trying to call is a method of a jQuery collection. So in order to make a jQuery object from the plain HTMLElement
you get returned from getting children[i]
, wrap that into the jQuery constructor, like so:
$(children[i]).children() // ...
这篇关于未捕获的TypeError:children [i] .children不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!