javascript添加一个下拉列表项的方法:创建一个新的option节点,然后添加到目标select对象中去,关键代码如下:
js code:
var objSelect = document.getElementById(select_id);
var new_opt = new Option(objItemText, objItemValue);
objSelect.options.add(new_opt);
1.get selected option
第一种方式 jQuery code:
$('#testSelect option:selected').text();//选中的文本
$('#testSelect option:selected') .val();//选中的value值
$("#testSelect ").get(0).selectedIndex;//索引
第二种方式 jQuery code:
$("#tesetSelect").find("option:selected").text();//选中的文本
$("#tesetSelect").find("option:selected").val();//选中的value值
$("#tesetSelect").find("option:selected").get(0).selectedIndex;//索引