2012-03-30 2 views
0

Ich habe folgenden Code, der für Radiobuttons funktioniert, aber müssen geändert werden, um Auswahlfelder die Änderung anstelle der Radiobuttons machen, ist das möglich?Ändern Dropdown-Werte von der Auswahl der vorherigen Dropdown-Menüs in Jquery

http://jsfiddle.net/Nksku/

HTML

ABC: <input type="radio" name="abc123" id="abc"/> 
123: <input type="radio" name="abc123" id="123"/> 

<select id="theOptions"> 
    <option value="1">1</option> 
    <option value="2">2</option> 
    <option value="3">3</option> 
    <option value="a">a</option> 
    <option value="b">b</option> 
    <option value="c">c</option> 
</select> 

jQuery

jQuery.fn.filterOn = function(radio, values) { 
    return this.each(function() { 
     var select = this; 
     var options = []; 
     $(select).find('option').each(function() { 
      options.push({value: $(this).val(), text: $(this).text()}); 
     }); 
     $(select).data('options', options); 
     $(radio).click(function() { 
      var options = $(select).empty().data('options'); 
      var haystack = values[$(this).attr('id')]; 
      $.each(options, function(i) { 
       var option = options[i]; 
       if($.inArray(option.value, haystack) !== -1) { 
        $(select).append(
        $('<option>').text(option.text).val(option.value) 
        ); 
       } 
      }); 
     });    
    }); 
}; 

$(function() { 
    $('#theOptions').filterOn('input:radio[name=abc123]', { 
     'abc': ['a','b','c'], 
     '123': ['1','2','3']   
    }); 
});​ 

Antwort

2

Ich könnte falsch verstanden, was Sie wollen, aber versuchen Blick auf diese:

http://jsfiddle.net/Nksku/2/

Möchten Sie eine von ihnen als Standard ausgewählt, und muss die zweite Box leer bleiben, bis Sie etwas aussortiert haben?

Verwandte Themen