关于jQuery的select取值、选择基本操作
1.清空(意味着情况select中的所用option,即文本的值)
$("#selectId").empty();
$("#selectId").html("");
$("#selectId").find(“option”).remove();
document.getElementById(“selectId”).options.length = 0;
document.formName.selectName.options.length = 0;
document.getElementById(“selectId”).innerHTML = “”;
2.获取选中默认值
$("#selectId").find(“option:selected”).val();
$(’#selectId option:selected’).val();
3.获取选中文本值
$("#selectId").find(“option:selected”).text();
KaTeX parse error: Expected 'EOF', got '#' at position 3: ('#̲selectId option…(’’);
for(var i=0;i<5;i++){
item.append(’’+i+’’);
}
5.设置一个select为请选择状态
$("#selectId").find(“option[value=’’]”).attr(“selected”,true);
6.jQuery添加/删除Select的Option项:
$("#select_id").append(“Text”); //为Select追加一个Option(下拉项)
$("#select_id").prepend(“请选择”); //为Select插入一个Option(第一个位置)
$("#select_id option:last").remove(); //删除Select中索引值最大Option(最后一个)
$("#select_id option[index=‘0’]").remove(); //删除Select中索引值为0的Option(第一个)
$("#select_id option[value=‘3’]").remove(); //删除Select中Value='3’的Option
$("#select_id option[text=‘4’]").remove(); //删除Select中Text='4’的Option
事件
7.change 改变下拉时触发;
KaTeX parse error: Expected 'EOF', got '#' at position 3: ("#̲select_id").cha…(this).val());
);
补充:因为页面翻页也是使用Ajax技术进行异步处理,当翻页后,原写法将失效,此时应该使用如下代码进行执行:
KaTeX parse error: Expected 'EOF', got '#' at position 25: …).on("change",'#̲select_id',func…(this).val());
});