【发布时间】:2017-07-14 04:47:46
【问题描述】:
我正在尝试使用 jquery 自动完成功能。我使用了search.php 文件并将数据作为
{
"id" : 1,
"name" : "ColdFusion",
"type" : "Tag"
},
{
"id" : 2,
"name" : "C#",
"type" : "Programming"
},
我想要什么,当我输入和建议出现并单击任何建议时,尊重的结果应该进入它们各自的输入字段。例如,我输入 Cold 并在建议中单击 ColdFusion,然后它的 id 应该进入 input id="id" 并命名为 input id="name" 并与类型类似。我想不出应该使用什么 jquery 事件,因为这是第一次使用自动完成功能。请帮助我从 jquery 站点发布了一个快速工作示例。
$( "#autocomplete" ).autocomplete({
source: [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby" ]
});
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>autocomplete demo</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete">
ID <input id="id"/>
NAME <input id="name"/>
TYPE <input id="type"/>
</body>
</html>
【问题讨论】:
标签: jquery json autocomplete