jquery 操作select

//通过id查找
//alert($(":password").attr("value"));
//alert($("#sel").find("option:selected").text());
//alert($("#sel").val());
//选中具体的对象

//获取select的值
//alert($("#sel").get(0).selectedIndex);
//在最前添加option
//$("#sel").prepend("<option value="-1">-1</option>");
//$("#sel").append("<option value="-5">-5</option>");

//移除最后一个

//$("#sel option:last").remove();
//移除第一个
//$("#sel option:first").remove();
//按照对应的index移除对象
//$("#sel option[index=0]").remove();

//按照对应的value移除对象
//$("#sel option[value='1']").remove();
//按照对应的text移除对象
$("#sel option[text='2']").remove();
var maxIndex = $("#sel option:last").attr("index");
var minIndex = $("#sel option:first").attr("index");
//alert(maxIndex);
//alert("first index is "+ minIndex);

原文地址:https://www.cnblogs.com/liuhouhou/p/3163788.html