使用<select multiple =“”>过滤div

时间:2015-05-18 20:32:33

标签: javascript jquery html

说我喜欢: &lt; div class =&#34;数字一二三&#34;&gt; ...&lt; / div&gt; &lt; div class =&#34;数字一三五&#34;&gt; ...&lt; / div&gt; &lt; div class =&#34;数字二四有六&#34;&gt; ...&lt; / div&gt; &lt; div class =&#34; number one two 4&#34;&gt; ...&lt; / div&gt; 我有一个选择: &lt; select id =&#34; filternumbers&#34;多个=#&34;多个&#34;&GT;     &lt; option value =&#34; one&#34;&gt; One&lt; / option&gt;     &lt; option value =&#34; two&#34;&gt; Two&lt; / option&gt;     &lt; option value =&#34; three&#34;&gt; Three&lt; / option&gt;     &lt; option value =&#34; four&#34;&gt; Four&lt; / option&gt;     &lt; option value =&#34; five&#34;&gt; Five&lt; / option&gt;     &lt; option value =&#34; six&#34;&gt; Six&lt; / option&gt; &LT; /选择&GT; 如何根据我的选择选择过滤div,比如&#34; two&#34;和&#34;四&#34; - 意味着只能看到最后两个div? 我知道我可以为单选菜单执行此操作: $(&#39;#filternumbers&#39;)。on(&#39; change&#39;,function(){     var number = $(this).val();     $(&#34; .numbers&#34)隐藏();     $(&#34; .numbers&#34)。hasClass(数字).show(); }); 但是如何进行多选?

2 个答案:

答案 0 :(得分:3)

您需要通过类名组合$.fn.filter div:

&#13;
&#13;
$('#filternumbers').on('change', function () {
    var number = $(this).val();
    var classNames = '.' + number.join('.');
    $(".numbers").hide().filter(classNames).show();
});
&#13;
.numbers {display: none;}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="filternumbers" multiple="multiple">
    <option value="one">One</option>
    <option value="two">Two</option>
    <option value="three">Three</option>
    <option value="four">Four</option>
    <option value="five">Five</option>
    <option value="six">Six</option>
</select>

<div class="numbers one two three">one two three</div>
<div class="numbers one three five">one three five</div>
<div class="numbers two four six">two four six</div>
<div class="numbers one two four">one two four</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

您可以检查首先检查的所有值,然后运行每个()检查已检查的值,然后使用过滤器显示所需的值

 @OneToMany(mappedBy = "evaluationType", cascade = CascadeType.ALL)
 private List<Member> memberList;

参考jsfiddle http://jsfiddle.net/gsmd2jd3/