分词器:
http://loopj.com/jquery-tokeninput/
当用户专注于输入时显示提示“输入搜索词”。是否可以使用 jQuery UI 的自动完成功能来做到这一点? http://jqueryui.com/demos/autocomplete/
我正在使用远程数据源,但我想也许分配一个长度为 1 的临时源([“输入搜索词”,“”])来自动完成,直到启动搜索?
最佳答案
这就是您要找的吗:更新演示 http://jsfiddle.net/vWJdT/ *旧版 => * 工作演示 http://jsfiddle.net/MQfEL/
我认为您正在寻找的是:http://loopj.com/jquery-tokeninput/
希望它适合您的事业:)
脚本
<script type='text/javascript' src="https://raw.github.com/loopj/jquery-tokeninput/master/src/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input.css">
<link rel="stylesheet" type="text/css" href="http://loopj.com/jquery-tokeninput/styles/token-input-facebook.css">
代码
$(document).ready(function() {
$("#demo-input-local-custom-formatters").tokenInput([{
"first_name": "Tats_innit",
"last_name": "Godfrey",
"email": "Tats_innit@mit.whatwhatwuthulk.edu",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jackson",
"email": "andre.jackson@yahoo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Jolly",
"email": "andre.jolly@uol.com.br",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
{
"first_name": "Andre",
"last_name": "Henderson",
"email": "andre.henderson@globo.com",
"url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
}
], {
propertyToSearch: "first_name",
resultsFormatter: function(item){ return "<li>" + "<img src='" + item.url + "' title='" + item.first_name + " " + item.last_name + "' height='25px' width='25px' />" + "<div style='display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.first_name + " " + item.last_name + "</div><div class='email'>" + item.email + "</div></div></li>" },
tokenFormatter: function(item) { return "<li><p>" + item.first_name + " <b style='color: red'>" + item.last_name + "</b></p></li>" },
});
});
工作图片
顺便说一句,我不是戈弗雷。
关于jQuery 自动完成在下拉列表中显示提示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12240563/