我想使用 EasyAutcomplete 插件为用户创建一个自动完成列表,然后通过 GET 方法发送与匹配字符串关联的值...而不是匹配字符串。
使用此代码
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="./EasyAutocomplete/easy-autocomplete.min.css">
<link rel="stylesheet" href="./EasyAutocomplete/easy-autocomplete.themes.min.css">
<script src="./EasyAutocomplete/jquery.easy-autocomplete.min.js"></script>
</head>
<body>
<form method="get" action="test.php">
<input id="provider-file" name="get_value"/>
<script>
$(document).ready(function() {
var options = {
url: "./EasyAutocomplete/file.json",
getValue: "name",
list: {
match: {
enabled: true
}
}
};
$("#provider-file").easyAutocomplete(options);
});
</script>
<div>
<a href=""><input type="submit" value="send"/></a>
</div>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
以及具有以下格式的 JSON 文件
[
{"name":"Bob","id":"1"},
{"name":"David","id":"2"},
{"name":"Steve","id":"3"},
...
]
Run Code Online (Sandbox Code Playgroud)
用户在提交 Bob 后被重定向到“test.php?get_value=Bob”,而我希望他被重定向到“test.php?get_value=1”(即发送“id”而不是“name”)。
有人可以帮助我吗?我在 EasyAutocomplete 文档中找不到任何答案。