不要遍历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();
}
})
};

上一篇:extern


下一篇:Unity3D判断触摸方向