首先来个下拉框
使用单位:
<select name="unitId" id="unitId">
<option value="">--请选择--</option>
</select>
然后使用ajax给下拉框拼接内容
我这里添加和修改是同一个页面。
回调成功拼接完毕后执行显示默认选中的方法
$.ajax({
url : '',//你的路径
type : 'post',
dataType : 'json',
success : function(data) {
var units = '';
for (var i = 0; i < data.length; i++) {
units += '<option value="'+data[i].uuid+'">'
+ data[i].name
+ '</option>';
}
$("#unitId").append(units);
vocationSelect("unitId","${device.unitId}");//这里是重点呀(*・ω< )
}
})
function vocationSelect(selectId, value) {//参数:下拉框的id,后台查到的对应的值
$("#"+selectId).val(value);
$("#"+selectId).parent().find(".uew-select-text").text($("#"+selectId).find(":selected").text());
}