jQuery UI自动完成不起作用
问题描述:
我试图使用jQuery UI自动完成但它不显示任何列表或任何东西。据我所知,没有必要用jQuery UI声明ul
或li
。jQuery UI自动完成不起作用
<html>
<head>
<link href="./jquery-ui.css" rel="stylesheet">
<script src="./jquery-1.11.1.js"></script>
<script src="./jquery-ui.js"></script>
</head>
<body>
<input id="pu_location" size="38" type="text" />
<input type="hidden" id="pu_locationID" />
<script>
Script is below.
</script>
</body>
</html>
脚本:
<script>
$(document).ready(function() {
$("#pu_location").autocomplete({
source: function(request, response) {
$.getJSON("/test.php", { country_code: "USA",term:$('#pu_location').val()},
function(data) {
alert(data[0].id);
var array =[];
for(key in data){
if (data[key].label!=''){
array.push(data[key].label);
}
}
alert(array);
response(array);
});
},
delay: 100,
minLength: 3
});
});
</script>
顺便说一句,在data
是完美的。 alert
表明一切都很好。
被修改: 它现在可以与Chrome一起使用,但不能与Firefox一起使用!
答
第一个线索: 删除:
$(function() {
你是想在这里创造selfexecuting JS的功能,但它是没有必要的,因为你已经在准备功能annonymus功能。
然后把一个日志只是线
$("#pu_location").autocomplete({
之前只是要确定正在执行该代码。第二条线索:你在回应数据时感受数据,然后创建并填充数组,最后传递给响应数据,那么处理的意义是什么?
你可以格式化代码位,这将是更多pleasent眼睛:) – Beri 2014-10-03 06:33:58
我试过了。我正在使用一个简单的文本编辑器。 – Arnold 2014-10-03 06:39:21
@Beri没有'$(function(){'和'function(request,response){'作为'$(“#pu_location”)之外的函数。'autocomplete {{代码看起来好多了,你知道.. 。 – Regent 2014-10-03 06:47:28