jQuery获取Select选择的Text和Value:
语法解释:
- $("#select_id").change(function(){
- var checkText=$("#select_id").find("option:selected").text();
- var checkValue=$("#select_id").val();
- var checkIndex=$("#select_id ").get(0).selectedIndex;
- var maxIndex=$("#select_id option:last").attr("index");
语法解释:
- $("#select_id ").get(0).selectedIndex=1;
- $("#select_id ").val(4);
- $("#select_id option[text='jQuery']").attr("selected", true);
-
-
jQuery添加/删除Select的Option项:
语法解释:
- $("#select_id").append("<option value='Value'>Text</option>");
- $("#select_id").prepend("<option value='0'>请选择</option>");
- $("#select_id option:last").remove();
- $("#select_id option[index='0']").remove();
- $("#select_id option[value='3']").remove();
- $("#select_id option[text='4']").remove();