这是我从xml解析出来的,但是太长了。有谁知道如何使它更短?“charList()”的数字和“if”的结构发生了变化。
var charList1;
var charList2;
var charList3;
var charList4;
var charList5;
$.ajax({
type: "get",
url: "XMLFile1.xml",
async: false,
dataType: "xml",
success: function (xml) {
$(xml).find('list').each(function () {
obj = $(this).find("title");
if (obj.text() == "1") {
charList1 = (obj.next().text());
} else if (obj.text() == "2") {
charList2 = (obj.next().text());
} else if (obj.text() == "3") {
charList2 = (obj.next().text());
} else if (obj.text() == "4") {
charList2 = (obj.next().text());
} else if (obj.text() == "5") {
charList2 = (obj.next().text());
}
});
}
});