function getSelectCity(pcode,id,selected = '') {
$.ajaxSettings.async = false;//同步请求
$.getJSON('sys/area/getAreaByPid.html', {
pid :pcode
}, function(data) {
if (data.success) {
var list = "";
$.each(data.data, function (key, item) {//遍历为下拉选赋值
if (item.value == selected){
list += "<option value='" + item.value + "' selected >" + item.text + "</option>";
}else {
list += "<option value='" + item.value + "'>" + item.text + "</option>";
}
});
$("#"+id).find("option:not(:first)").remove();
$("#"+id).append(list); //填充
//处理一下id兼容
$("#"+id).selectpicker('refresh');
}else {
layer.msg(data.msg);
}
});
}
select标签自定义下拉选
最新推荐文章于 2024-07-15 17:50:58 发布