下面是我從菜鳥教程裡面看到的Demo。如下
現在的功能是我選某個Name,然後直接就可以填到input框裡,隨後插入到數據庫。
現在我想實現的功能是,填入的是名字,但是存儲到數據庫裡的是id,這個怎麼寫?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 自動完成(Autocomplete) - 默認功能</title>
<link rel="stylesheet" href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
<script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="jqueryui/style.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">標簽:</label>
<input id="tags">
</div>
</body>
</html>
服務器端加上一個邏輯,根據name去找id,然後存id