jquery select
jquery 清空 option $(“#sel”).empty();
添加4法:
1:$('#example').append('<option value="foo" selected="selected">Foo</option>');
2:('#example').append(new Option('Foo', 'foo', true, true));
3:var options = $('#example').attr('options');
options[options.length] = new Option('Foo', 'foo', true, true
4:
var newOptions = {
02 'red' : 'Red',
03 'blue' : 'Blue',
04 'green' : 'Green',
05 'yellow' : 'Yellow'
06 };
07 var selectedOption = 'green';
08
09 var select = $('#example');
10 if(select.prop) {
11 var options = select.prop('options');
12 }
13 else {
14 var options = select.attr('options');
15 }
16 $('option', select).remove();
17
18 $.each(newOptions, function(val, text) {
19 options[options.length] = new Option(text, val);
20 });
21 select.val(selectedOption);