简体   繁体   English

可扩展的多选下拉列表

[英]Expandible Multiselect Dropdown list

How can I get an expandable [tree view] multiselect dropdown list?如何获得可扩展的 [树视图] 多选下拉列表?

For example, from the below snapshot, if I have sub-list for Animals [Cat, Cow etc] is there any plugin as such that would show a + sign and when clicked, it would show the sub-list in the same dropdown like a tree view?例如,从下面的快照中,如果我有 Animals [Cat, Cow etc] 的子列表,是否有任何插件会显示 + 号,当单击时,它会在同一个下拉列表中显示子列表,如树视图?

在此处输入图像描述

Any advice?有什么建议吗?

Just a select tag alone, I know you can't.只是一个 select 标签,我知道你不能。 In your case, you need to create a customized select box.在您的情况下,您需要创建一个定制的 select 盒子。

  • This can be done using a combination of html tags, just like the treeview plugin of JavaScript library like JQuery UI .这可以使用 html 标签的组合来完成,就像 JavaScript 库的treeview插件,如Z6A2D7208853DAFCCB796 But you commented to @Edgar that there is no multi-select for that.但是您对@Edgar 评论说没有多选。
  • Also embedding a flash or a java plugins can be a solution.嵌入 flash 或 java 插件也是一种解决方案。

I guess my examples solution didn't give you the exact thing you wanted.我想我的示例解决方案没有给你你想要的确切的东西。 I'll just give a simple example that could be a help to answer your question.我只举一个简单的例子,可能有助于回答你的问题。 This is to create a customized select box.这是为了创建一个定制的 select 盒子。

Customized Select Box定制Select盒子

How to create the customized select box:如何创建定制的 select 盒子:

  1. Create a div that will be a container of the list.创建一个将作为列表容器的 div。

    <div id="treeSelect">

  2. Add style on the div that will behave like a select box.在 div 上添加样式,其行为类似于 select 框。

    #treeSelect{height: 100px;width: 150px;border: 1px solid #000;overflow: auto;}

  3. Add the content of the main list along with the sublist on the div.将主列表的内容与 div 上的子列表一起添加。 Include all possible style that could be use to format the content to be more like a tree view list.包括可用于将内容格式化为更像树视图列表的所有可能样式。

     <span class="mainList">All</span> <br /> <span class="expand" onClick="expand('animals', this);">[+]</span><span class="mainList">Animals</span> <br /> <ul id="animals" class="subList"> <li><input type="checkbox" name="animals" value="Cat">Cat</li> <li><input type="checkbox" name="animals" value="Cow">Cow</li> <li><input type="checkbox" name="animals" value="Cat">Dog</li> </ul>
  4. Add a script that will handle how to view the sublist.添加将处理如何查看子列表的脚本。

    function expand(list, view){ function 展开(列表,查看){

     var listElement = document.getElementById(list); var defaultView = '[+]'; if(view.innerHTML == defaultView){ listElement.style.display = "block"; view.innerHTML = '[-]'; } else { listElement.style.display = "none"; view.innerHTML = '[+]'; }

    } }

I cannot put all the code so please see the jsfiddle for the complete code.我无法放置所有代码,因此请参阅jsfiddle以获取完整代码。

I know this is not the exact things you wanted, but I guess it is close to what you need.我知道这不是您想要的确切东西,但我想它接近您需要的东西。 You can change the style based on your taste and needs.您可以根据自己的品味和需求更改样式。 I hope this can be a help and give you idea how to solve your question.我希望这对您有所帮助,并让您知道如何解决您的问题。

You could use the treeview plugin or the jsTree plugin您可以使用treeview 插件jsTree 插件

Hope this helps.希望这可以帮助。 Cheers干杯

You can use an <optgroup> for each main category whose children are hidden by default, and when clicking on the <optgroup> label it can simply unhide the child <option> (s).您可以为每个默认隐藏子级的主类别使用<optgroup> ,当单击<optgroup> label 时,它可以简单地取消隐藏子<option> (s)。

Something like the following:类似于以下内容:

In your CSS:在您的 CSS 中:

#categories optgroup option { display: none; }

In your HTML:在您的 HTML 中:

<select name="categories" id="categories">
    <optgroup label="+ Animals">
        <option value="bird">Bird</option>
        <option value="dog">Dog</option>
        <option value="cat">Cat</option>
    </optgroup>
</select>

In your JavaScript (using jQuery):在您的 JavaScript 中(使用 jQuery):

$('#categories > optgroup').click(function(){
    $(this).children().toggle();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM