本文介绍了接受用户输入以构建分层树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



下面的代码给出了项目及其子项目的树状视图,..以分层格式显示,...但是我不想给输入的项目1,子项目1等进行硬编码,...我想给输入,这样它将变成通用代码,并为我们提供的任何输入显示层次树视图..
我尝试提供一些变量,但对我来说不起作用.
1)请问您对此有何建议.您还有其他想法使用HTML/JAVASCRIPT构建层次树吗?
2)我也尝试过使用DOM,但是它没有用,..我不知道如何正确使用DOM,如果您对DOM有任何了解,请提出建议

< code>
< ul>
< li>
< a href =#" onclick ="toggle(" node1)">项目1</a>
< ul id ="node1" style ="display:none">
< li>子项目1</li>
< li>
< a href =#" onclick ="toggle(" node2)">子项目2</a>
< ul id ="node2" style ="display:none">
< li>子子项目1</li>
< li>子子项目2</li>
</ul>
</li>
< li>子项目3</li>
</ul>
</li>
< li>
< a href =#" onclick ="toggle(" node3)">项目2</a>
< ul id ="node3" style ="display:none">
< li>子项目1</li>
< li>子项目2</li>
</ul>
</li>
< li>项目3</li>
</ul>

</code>

Hi,

The below code gives a Treeview of Items and their sub-items,.. It shows in the hierarchical format,... but instead of hard-coding the input Item 1 , Sub-item 1 etc,..., i wanna give an input so that it will become a generic code and show the hierarchical tree view for any input we give,..
I tried giving some variables but it didn''t work for me..
1)Could you please suggest me on this.. and also do u have any other ideas to build a hierarchical tree using HTML/JAVASCRIPT..
2)I also tried using DOM but it didn''t work,.. I didn''t know how to use DOM properly, suggest me if you have any idea about DOM

<code>
<ul>
<li>
    <a href="#" onclick="toggle(''node1'')">Item 1</a>
    <ul id="node1" style="display:none">
      <li>Sub-item 1</li>
      <li>
        <a href="#" onclick="toggle(''node2'')">Sub-item 2</a>
        <ul id="node2" style="display:none">
          <li>Sub-sub-item 1</li>
          <li>Sub-sub-item 2</li>
        </ul>
      </li>
      <li>Sub-item 3</li>
    </ul>
  </li>
  <li>
    <a href="#" onclick="toggle(''node3'')">Item 2</a>
    <ul id="node3" style="display:none">
      <li>Sub-item 1</li>
      <li>Sub-item 2</li>
    </ul>
  </li>
  <li>Item 3</li>
</ul>

</code>

Thanks in advance!

推荐答案




这篇关于接受用户输入以构建分层树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 01:17