<script>
$(document).ready(function() {
var myArr = [];
$.ajax({
type: "GET",
url: "doctors.xml", // XML File location
dataType: "xml",
success: parseXml,
complete: setupAC,
failure: function(data) {
alert("XML File could not be found");
}
});
function parseXml(xml)
{
//find every query value
$(xml).find("doctor").each(function()
{
myArr.push($(this).attr("label"));
});
}
function setupAC() {
var limit = 10;
$("input#searchBox").autocomplete({
source: myArr,
minLength: 2,
select: function(event, ui) {
$("input#searchBox").val(ui.item.value);
$("#searchForm").submit();
}
});
}
});
</script>
答案 0 :(得分:2)
替换此行
$("#searchForm").submit();
与
return false;
如果您使用回车键进行选择,则可能需要阻止默认事件
$("input#searchBox").keydown(function(event){
if(event.keyCode == 13) {
if($("input#searchBox").val().length==0) {
event.preventDefault();
return false;
}
}
});