简体   繁体   English

选择框-显示/不显示

[英]Select boxes - Display/No display

I have a page which allows users to comple one - three select boxes. 我有一个页面,允许用户填写一个-三个选择框。

The first select box is shown on the page when it loads, then the user can click "Add filter 2/3/4" 加载时页面上会显示第一个选择框,然后用户可以单击“添加过滤器2/3/4”

See code below: 参见下面的代码:

<div id="filter2"><a href="#">Add Filter 2</a></div>           
    <div id="filtertwo">           

      <label class="">Filter 2</label>
      <select class="full-width" data-placeholder="Select Filter" name="filter2" data-init-plugin="select2">

      <option value="test">Test</option>
      <option value="test1">Test1</option>
      </select>   

    <script>
        $(document).ready(
        function() {
            $("#filter2").click(function() {
                $("#filtertwo").toggle();
            });
        });

    </script>

    <style>
         #filtertwo {
        display: none;
    }
    </style>

The coding is the same for each of my select boxes. 每个选择框的编码都相同。 I would like to just show text "Add New Filter" only once, is this possible? 我只想显示一次“添加新过滤器”文本,这可能吗?

I have attached a screenshot so you can see my current page: 我已附上屏幕截图,因此您可以看到我的当前页面: 在此处输入图片说明

<div id="filter2"> <a id="filterLink" href="#"> Add New Filter </a> </div>

<script>
     $(document).ready(function(){
          $("#filter2").click(function() {
              $("#filtertwo").toggle();
              $("filterLink").hide();
              $("filter2").innerHTML = "<a id='filterLink' href='#'> Add Filter 2 </a>";
          });
     });
</script>

Now Repeat the code innerHTML how many time you want that link. 现在,重复代码innerHTML您希望该链接多少次。

If i understand you properly. 如果我正确理解你的话。 Consider following snippet: 考虑以下代码段:

$(document).ready(
    function() {
        $("#filter1,#filter2, #filter3").click(function() {
            $('.filter').hide();
            $(this).next('.filter').toggle();
        });
    });

DEMO 演示


If you want to show only one filter link: 如果您只想显示一个过滤器链接:

$(document).ready(
    function() {
        $(".filter-link").click(function() {
            $(".filter-link").hide();
            $(".filter-link").not(this).show();
            $('.filter').hide();
            $(this).next('.filter').toggle();
        });
    });

Updated DEMO 更新了演示

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

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