dynatree的结构是这样的:
<ul class="dynatree-container">
<li class="">
<span class="dynatree-node dynatree-has-children dynatree-exp-c dynatree-ico-c">
<a class="dynatree-title" href="#">Alimentary</a>
</span>
</li>
<li class="">
<span class="dynatree-node dynatree-expanded dynatree-has-children dynatree-exp-e dynatree-ico-e">
<a class="dynatree-title" href="#">Fruits</a>
</span>
<ul style="">
<li class="">
<span class="dynatree-node dynatree-exp-c dynatree-ico-c">
<a class="dynatree-title" href="#">Banans</a>
</span>
</li>
</ul>
</li>
<li class="">
<span class="dynatree-node dynatree-has-children dynatree-exp-c dynatree-ico-c">>
<a class="dynatree-title" href="#">Cosmetics</a>
</span>
</li>
</ul>
我想搜索数据,如果树中存在“菠萝”,以粗体显示。在javascript中我写了一个方法onkeyPressed:
function Search(value)
{
for(var i=0;i<document.getElementsByTagName('li').length;i++)
{
var node=document.getElementsByTagName('dynatree-title')
if (node.data.href ==value) {
//expand the tree
}
}
}
我不确定如何访问所有节点以搜索该值。有人有想法吗?