0

过滤正在工作,但我需要使用这两个选择下拉菜单来暗示全选。我需要的是两个选择下拉菜单都有一个全选。

HTML:

<select name="select1" id="select1">
<option Value="">All</option>
        <option Value="2013-10-10">2013-10-10</option>
        <option Value="2013-10-09">2013-10-09</option>
        <option Value="Onion">Onion</option>
        <option Value="Wewe">Wewe</option>
</select>


<select name="select2" id="select2">
        <option Value="2013-10-10">2013-10-10 Style 1</option>
        <option Value="2013-10-10">2013-10-10 Style 2</option>
        <option Value="2013-10-10">2013-10-10 Style 3</option>
        <option Value="2013-10-09">2013-10-09 Style 1</option>
        <option Value="2013-10-09">2013-10-09 Style 2</option>
        <option Value="2013-10-09">2013-10-09 Style 3</option>
        <option Value="Orange">Orange Style 4</option>
        <option Value="Onion">Onion Style 1</option>
        <option Value="Onion">Onion Style 2</option>
        <option Value="Wewe">wewe Style 2</option>
</select>

JavaScript:

$("#select1").change(function() { 
if($(this).data('options') == undefined){
    /*Taking an array of all options-2 and kind of embedding it on the select1*/
    $(this).data('options',$('#select2 option').clone());
    } 
var id = $(this).val();
var options = $(this).data('options').filter('[value=' + id + ']');
$('#select2').html(options);
});

演示:http: //jsfiddle.net/fRuhn/520/

4

1 回答 1

1
$("#select1").change(function() { 
    if($(this).data('options') == undefined){
        /*Taking an array of all options-2 and kind of embedding it on the select1*/
        $(this).data('options',$('#select2 option').clone());
    } 
    var id = $(this).val();
    var options = $(this).data('options').filter(function() {
        return  (id === '') || id === $(this).val();
    });
    $('#select2').html(options);
    $('#select2').val($('#select2 option:first').val());
});
于 2013-10-10T11:00:33.923 回答