jQuery 自动完成在下拉列表中显示提示文本

标签 jquery jquery-ui jquery-ui-autocomplete

分词器:

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>" },
          });
        });​

工作图片

顺便说一句,我不是戈弗雷。

enter image description here

enter code here

关于jQuery 自动完成在下拉列表中显示提示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12240563/

相关文章:

javascript - jQueryUI Autocomplete - 如何将搜索词与关键字列表匹配并显示匹配结果?

javascript - 带有属性的 jQuery UI 自动完成文本

jquery - 如何将 CSS 类名传递给 jQuery 自动完成组合框?

jquery - vue.js 'document.getElementById' 速记

javascript - 按 DESC 排序输入会破坏 jQuery UI 自动完成功能

javascript - 我们可以对同一个元素应用两次hoverintent插件吗? (JQuery)

javascript - jQuery UI 可排序 - 当用户开始从特定 block 拖动元素时执行某些操作

jquery - jquery 的 CSS Transitions 不起作用

jQuery:循环插件和 100% 高度

javascript - 如何获取输入值并将其放入 angularJS 中的变量中?