<html>
<select id='problemTypeId'><option>请选择</option></select>
<select id='problemTypeId1'></select>
<input value="a3" id="input_1">
<button id="oo">点击</button>
</html>
<script type="text/javascript">
$(document).ready(function(){
$("#oo").click(function(){
alert('problemTypeId=+' +$("#problemTypeId ").val());
alert('problemTypeId1=+' +$("#problemTypeId1 ").val());
})
// 1 添加数组
var dataList = ["123", "234", "354"];
for (var i = 0; i < dataList.length; i++) {
//先创建好select里面的option元素
var option = document.createElement("option");
//转换DOM对象为JQ对象,好用JQ里面提供的方法 给option的value赋值
$(option).val(dataList[i]);
//给option的text赋值,这就是你点开下拉框能够看到的东西
$(option).text(dataList[i]);
//获取select 下拉框对象,并将option添加进select
$('#problemTypeId').append(option);
}
//2 添加对象
var dataList1= [{
"aa": "1010",
"bb": "E0-1",
}, {
"aa": "1020","bb": "S0-2",
}, {
"aa": "1025",
"bb": "M0-3",
}]
for (var j = 0; j < dataList1.length; j++) {
//先创建好select里面的option元素
var option1 = document.createElement("option");
//转换DOM对象为JQ对象,好用JQ里面提供的方法 给option的value赋值
$(option1).val(dataList1[j].bb);
//给option的text赋值,这就是你点开下拉框能够看到的东西
$(option1).text(dataList1[j].bb);
//获取select 下拉框对象,并将option添加进select
$('#problemTypeId1').append(option1);
}
})
</script>