jQuery獲取Select選擇的Text和Value: app
1. $("#select_id").change(function(){//code...}); //爲Select添加事件,當選擇其中一項時觸發 2. var checkText=$("#select_id").find("option:selected").text(); //獲取Select選擇的Text 3. var checkValue=$("#select_id").val(); //獲取Select選擇的Value
jQuery設置Select選擇的Text和Value: code
$("#select_id ").val(4); //設置Select的Value值爲4的項選中 $("#province option[value='江西省']").attr("selected", true);
jQuery添加/刪除Select的Option項:事件
1. $("#select_id").append("<option value='Value'>Text</option>"); //爲Select追加一個Option(下拉項) 2. $("#select_id").prepend("<option value='0'>請選擇</option>"); //爲Select插入一個Option(第一個位置) 3. $("#select_id option[text='xx']").remove(); //刪除Select中Text='xx'的Option