jQuery操作select

//获取第一个option的值

$('#testoption:first').val();

//最后一个option的值

$('#testoption:last').val();

//获取第二个option的值

$('#testoption:eq(1)').val();

//获取选中的值

$('#test').val();

$('#testoption:selected').val();

//设置值为2的option为选中状态

$('#test').attr('value','2');

//设置第一个option为选中

$('#testoption:last').attr('selected','selected');

$("#test").attr('value',$('#testoption:last').val());

$("#test").attr('value',$('#testoption').eq($('#testoption').length-1).val());

//获取select的长度

$('#testoption').length;

//添加一个option

$("#test").append("<optionvalue='9'>ff</option>");

$("<optionvalue='9'>ff</option>").appendTo("#test");

//添除选中项

$('#testoption:selected').remove();

//指定项选中

$('#testoption:first').remove();

//指定值被删除

$('#testoption').each(function(){

if($(this).val()=='5'){

$(this).remove();

}

});

$('#testoption[value=5]').remove();

//获取第一个Group的标签

$('#testoptgroup:eq(0)').attr('label');

//获取第二group下面第一个option的值

$('#testoptgroup:eq(1)ption:eq(0)').val();

//设置默认值

$("#test).get(0).options[0].selected=true;//options[0]表示设置第一个为默认值