I.jquery获取select选择的Text和Value:
1. var checkText=$("#select-id").find("option:selected").text(); //获取select-id选择的Text
2. var checkValue=$("#select-id").val(); //获取select-id选择的option Value
3. var checkIndex=$("#select-id ").get(0).selectedIndex; //获取select-id选择的索引值
4. var maxIndex=$("#select-id option:last").attr("index"); //获取select-id最大的索引值</span>
II.jQuery添加/删除select-id的Option项
1. $("#select-id").append("<option value='Value'>Text</option>"); //为select-id追加一个Option(下拉项)
2. $("#select-id").prepend("<option value='0'>请选择</option>"); //为select-id插入一个Option(第一个位置)
3. $("#select-id option:last").remove(); //删除select-id中索引值最大Option(最后一个)
4. $("#select-id option[index='0']").remove(); //删除select-id中索引值为0的Option(第一个)
5. $("#select-id option[value='3']").remove(); //删除select-id中Value='3'的Option
6. $("#select-id option[text='4']").remove(); //删除select-id中Text='4'的Option
7. $("#select-id").empty(); //清空select-id内容
代码如下:
$(function(){
$('#select-id').change(function(){
var val=$(this).val();
$('#div').show();
$('#sel-hylx').attr("value",'1');
$("#select-id2 option[value='-1']").remove();
if(val==2){
$("#select-id2").prepend("<option value='-1'>无选择</option>");
$('#select-id2').attr("value",'-1');
$('#hylx').css("display", "none");
}
});
})