2010-12-04 54 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