1.概念
<select id="mineType2" onChange="getChild(this,1)">
<option value ="volvo">Volvo</option>
<option value ="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<select&> 元素中的 <option> 标签用于定义列表中的可用选项。
2.jq获取select选中值
var value=$("select option:selected").val()
或者
var value=$("select option:selected").text()
3.jq将动态获取的值设置为选中状态
$(".rs-club option:selected").text("xxx");
4.设置select可以选择
$("#mineType2").removeAttr("disabled");
5.设置select不可以选择
$("#mineType2").attr("disabled", "disabled");
6.jqery 添加
$("#cengWei").append("<option selected='selected' value='" + a.cengWei + "'>" + a.cengWei + "</option>");
===============================================
var obj=document.getElementById('mineType');
obj.options.add(new Option("请选择矿区",""));
obj.options.add(new Option("色连二矿","selian2"));
obj.options.add(new Option("泊江海子","bojianghaizi"));
obj.options.add(new Option("唐家会","tangjiahui"));
obj.children[3].selected=true;
7.juery 设置选择项
var selectid_cengwei = document.getElementById("cengWei");
for (i = 0; i < selectid_cengwei.length; i++) {
if (selectid_cengwei[i].text == a.cengWei)
selectid_cengwei[i].selected = true;
}
8.二级联动
function getChild(currFylx) {
//当前 所选择 的费用类型
// var currFylx_value = currFylx.options[currFylx.selectedIndex].value;
var mine_type = $("#mineType2 option:selected");
var select_mine_type = mine_type.val();
var data = {}
// data["jiance_danyuan"]=currFylx_value
$.ajax({
url: '/wz_get_workname/' + select_mine_type,
type: 'GET',
async:false,
dataType: 'JSON',
success: function (data) {
console.log(data);
var obj2 = document.getElementById('jianCeDanYuan');
var cengWei = document.getElementById('cengWei');
$("#jianCeDanYuan").html("");
$("#cengWei").html("");
cengWei.options.add(new Option("请选择", "请选择"));
obj2.options.add(new Option("请选择", "请选择"));
for (var i = 0; i < data.length; i++) {
obj2.options.add(new Option(data[i].workName, data[i].workName));
}
}
});
}