大家好,我是java-script中的新手。所以我希望你能帮助我。当用户将数据设置为城市字段时,我想自动在国家字段中设置数据。 我有一个XML文件:使用jQuery-UI自动完成选择选项时设置多个输入值
<ROWSET>
<ROW>
<city></city>
<country></country>
</ROW>
</ROWSET>
在HTML文档中,我有两个输入字段
<input id="id_city">
<input id="country">
这里是我的js代码:
$.ajax({
url: "/media/xml/country.xml", //your url
type: "GET", //may not need this-fiddle did-default is GET
dataType: "xml",
success: function(xmlResponse) {
var data = $("ROW", xmlResponse).map(function() {
return {
value: $("city", this).text() + ", " + ($.trim($("country", this).text()) || "(unknown country)")
};
}).get();
$("#id_city").autocomplete({
source: function(req, response) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp("^" + re, "i");
response($.grep(data, function(item) {
return matcher.test(item.value);
}));
},
minLength: 2,
select: function(event, ui) {
$("p#result").html(ui.item ? "Selected: " + ui.item.value + ", cityId: " + ui.item.id : "Nothing selected, input was " + this.value);
}
});
}
});
我不知道如何设置自动数据到国家/地区 谢谢。
问题是什么? – m02ph3u5
对不起,我不知道如何设置自动数据到国家字段 –