- <select id="test">
- <option value ="volvo">Volvo</option>
- <option value ="saab">Saab</option>
- <option value="opel">Opel</option>
- <option value="audi">Audi</option>
- </select>
获取 select 选中的 text :
$("#test").find("option:selected").text();
获取 select 选中的 value:
$("#test").val();
获取 select 选中的索引:
$("#test").get(0).selectedindex;
设置 select:
设置 select 选中的索引:
$("#test").get(0).selectedindex=index;//index 为索引值
设置 select 选中的 value:
- $("#test").attr("value","normal");
- $("#test").val("normal");
- $("#test").get(0).value = value;
设置 select option 项:
- $("#test").append("<option value='value'>text</option>"); // 添加一项 option
- $("#test").prepend("<option value='0'> 请选择 </option>"); // 在前面插入一项 option
- $("#test option:last").remove(); // 删除索引值最大的 option
- $("#test option[index='0']").remove();// 删除索引值为 0 的 option
- $("#test option[value='3']").remove(); // 删除值为 3 的 option
- $("#test option[text='4']").remove(); // 删除 text 值为 4 的 option
清空 select:
$("test").empty();
来源: http://www.bubuko.com/infodetail-3197873.html