0

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">&gt; 
         <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       
        }        
       }    
    }

我不确定如何访问所有节点以搜索该值。有人有想法吗?

4

2 回答 2

1

您可以使用 Jquery 搜索节点:

function Search(value){
    $(".dynatree-title").each(function(){
        if($(this).text() == value){
            $(this).html("<strong>"+$(this).text() +"</strong>");
        }
    });
}
于 2013-06-04T09:05:23.943 回答
0

如果我理解正确,您应该检查innerHTML,而不是href:

if (node.innerHTML == value)

然后继续你的代码。

于 2013-06-04T08:54:14.073 回答