2010-12-04 94 views
1
<li> 
<input type="checkbox" name="post_category[]" id="post_category" value="1"> 
parent1(category_names) 
</li> 
<li> 
<input type="checkbox" name="post_category[]" id="post_category" value="2"> 
&nbsp;child1 of parent1 
</li> 
<li> 
<input type="checkbox" name="post_category[]" id="post_category" value="3"> 
&nbsp;child2 of parent1 
</li> 

类别名称在树形视图中列出。复选框的值包含类的ID在jquery中动态添加节点

问题: * 我需要在此列表中添加类动态 *

我得到new_category的名字,从用户parent_category_id。 我需要添加类别作为相同的格式下面的父母

回答

1

为什么不是简单的像:

var objList = document.getElementById('mylist'); // need to add ID to OL or UL tag 
var objNode = null; 

if (objList != null) { 
    objNode = document.createElement('li'); 
    if (objNode != null) { 
     objNode.innerHTML = '~~~CHECKBOX HTML~~~'; 
     objList.appendChild(objNode); 
    } //if 
} //if 
0

问题是,你没有任何方式(短使用正则表达式来解析文本),以确定哪个元素是一个父母和哪个是一个孩子。我建议添加一个parentchild类,并使用嵌套,以便child出现在parent下。否则,您必须扫描每个li才能找到您想要的父母之后,但在下一个父母之前的最后一个孩子。

+0

我可以通过了解复选框(即PARENT_ID) – 2010-12-04 17:40:47