法2.从json读取
<input class="easyui-combobox" name="" id="" data-options="valueField:'id',textField:'name',url:'json文件或AJAX事件'" />
var opt = '<option value="1">呵呵1</option><option value="2">呵呵2</option>'$('#id').html(opt)
id就是select标签的id值,这是用jQuery
document.getelementbyid(id).html=opt js方式
首选jQuery
json测试文件
{
"first":[
{"name":"001"},
{"name":"002"},
{"name":"003"},
{"name":"004"},
{"name":"005"},
{"name":"006"},
{"name":"007"}
]
}
<!doctype html><html>
<head>
<meta charset="utf-8">
<title>下拉列表</title>
</head>
<body>
<select id="asd">
</select>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<script>
$(function () {
$.ajax({
type:"get",
url:"ceshi.json",
async:true,
dataType:"json",
success:function (data) {
$.each(data.first, function(i,item) {
var sele='<option value="'+item.name+'">'+item.name+'</option>'
$("#asd").append(sele)
})
}
})
})
</script>
</body>
</html>