html:
<select name=”device-model” id=”device-model” class=”select” style=”width: 100px;”>
<option value=”” selected>全部</option>
</select>
js:
// 下拉框
$(function () {
$.ajax({
url: ‘http://localhost/ThinkPHP/index.php/IotRouter/Type/query’,//请求地址
data: {type: “device_model”},//传给后台的数据
dataType: ‘json’,
async: false,
timeout: 1000,
type: ‘post’,
success: successFun,
error: errorFun
});
function successFun(result) {
for (var i = 0; i < result.data.length; i++ ) {
var model = result.data[i].type_name;
$(“#device-model”).append(“<option>”+ model +”</option>”);
}
}
function errorFun(result) {
}
})
版权声明:本文为yjreset原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。