不要遍历dom

function selectProvince() {
$.ajax(
{
type: "post",
url: "/province/getStrType",
data: { "type": "province" },
success: function (msg) {
for (var i = 0; i < msg.length; i++) {
$("#province").append("<option value=" + msg[i].CODE + ">" + msg[i].PROVINCE + "</option>");
}
selectCity();
}
})
};

上面这种写法遍历dom,不好,具体哪不好,以后研究,应该下面的写法

function selectProvince() {
$.ajax(
{
type: "post",
url: "/province/getStrType",
data: { "type": "province" },
success: function (msg) {
alert(msg);

var str;
for (var i = 0; i < msg.length; i++) {
str+="<option value=" + msg[i].CODE + ">" + msg[i].PROVINCE + "</option>";
}
$("#province").append(str);
selectCity();
}
})
};

原文地址:https://www.cnblogs.com/zkwarrior/p/6209364.html