select获取选中值
第一种方式
$('#testSelectoption:selected').text();//选中的文本
$('#testSelect option:selected').val();//选中的值
$("#testSelect").get(0).selectedIndex;//索引
第二种方式
$("#tesetSelect").find("option:selected").text();//选中的文本
$("#tesetSelect").find("option:selected").val();选中的值
$("#tesetSelect").find("option:selected").get(0).selectedIndex;索引
动态添加select中的option选项
var optionObj =document.createElement("option");
optionObj.value =zyxmxx[i].ZYJGXMBH;
optionObj.text =zyxmxx[i].ZYJGXMMC;
dom添加:
document.getElementById("txt_JSYDMC").options.add(optionObj);
jquery添加
$("#" +divID).get(0).options.add(optionObj);
select清空
方法1:$("#txt_JSYDMC").empty();
方法2:
var o = document.getElementById("dll_TableName");
o.length =0;
jquery动态设置select选中
红色字体部分为控件的id
for (var j = 0; j <$("#sel_exFieldType_"+ i + " option").length; j++) {
if ($("#sel_exFieldType_" + i + " option").get(j).value ==sc.SelectCondition[i].ExType) {
$("#sel_exFieldType_" + i + "option").get(j).selected= true;
};
}
Jquery跟据index设置选中值
/*设置select选中值 */
$("select[name='project.customerId']").get(0).selectedIndex=hideSelectValindex;