我尝试使用JQuery自动完成功能,但出现此错误:
Uncaught SyntaxError: Unexpected token < in JSON at position 2
我的代码是这样的,HTML:
<div id="fastSearchBox" class="fastSearchBox">
<span style="direction: rtl; float: right;">search</span>
<input id="fastSearchInput" type="text" style="width: 150px; margin-right: 10px;"></input>
</div>
JavaScript:
users = [{"data":1,"value":"foo"}];
$("#fastSearchInput").autocomplete({
source: users,
select: function (event, ui)
{
}});
我不知道为什么,但是改变source
以lookup
使其起作用
具有标签和值属性的对象数组:[{标签:“ Choice1”,值:“ value1”},...]
自动完成功能期望使用上述格式的数组。将您的数组更改为以下内容:
<body>
<div id="fastSearchBox" class="fastSearchBox">
<span style="direction: rtl; float: right;">search</span>
<input id="fastSearchInput" type="text" style="width: 150px; margin-right: 10px;">
</div>
</body>
var users = [
{data: 1, value: "foo" },
{data: 2, value: "foo2" },
{data: 3, value: "foo3" }
];
$( "#fastSearchInput").autocomplete({
source: users
});
$( "#fastSearchInput").on( "autocompleteselect", function( event, ui ) {
alert(ui.item.data);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句