久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

實現 jquery UI 自動完成以在您鍵入“@"時顯示

Implementing jquery UI autocomplete to show suggestions when you type quot;@quot;(實現 jquery UI 自動完成以在您鍵入“@時顯示建議)
本文介紹了實現 jquery UI 自動完成以在您鍵入“@"時顯示建議的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用 jquery UI AutoComplete 來允許用戶使用@mentions 標記朋友.默認情況下,當您將焦點放在文本框上時,自動完成建議就會出現.如何讓建議僅在您鍵入@"時出現?這是我到目前為止的代碼:

I'm using jquery UI AutoComplete to allow users to tag friends using @mentions. By default, the autocomplete suggestions appear when as soon you put focus on the textbox. How can you make the suggestions appear only when you type "@"? This is the code I have so far:

var availableTags = [
            "ActionScript",
            "AppleScript",
            "Asp",
            "BASIC",
            ];
$("#tags").autocomplete({
    source: availableTags,
    minLength: 0
});

推薦答案

您可以通過向自動完成的 source 選項提供一個函數來實現:

You can do this by providing a function to the source option of autocomplete:

var availableTags = [ /* Snip */];

function split(val) {
    return val.split(/@s*/);
}

function extractLast(term) {
    return split(term).pop();
}

$("#tags")
// don't navigate away from the field on tab when selecting an item
.bind("keydown", function(event) {
    if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
        event.preventDefault();
    }
}).autocomplete({
    minLength: 0,
    source: function(request, response) {
        var term = request.term,
            results = [];

        /* If the user typed an "@": */
        if (term.indexOf("@") >= 0) {
            term = extractLast(request.term);
            /* If they've typed anything after the "@": */
            if (term.length > 0) {
                results = $.ui.autocomplete.filter(
                availableTags, term);
            /* Otherwise, tell them to start typing! */
            } else {
                results = ['Start typing...'];
            }
        }
        /* Call the callback with the results: */
        response(results);
    },
    focus: function() {
        // prevent value inserted on focus
        return false;
    },
    select: function(event, ui) {
        var terms = split(this.value);
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push(ui.item.value);
        // add placeholder to get the comma-and-space at the end
        terms.push("");
        this.value = terms.join("");
        return false;
    }
});

這是一個工作示例:http://jsfiddle.net/BfAtM/2/

請注意,這幾乎與 此演示相同,除了要求用戶鍵入@".該代碼位于 source 選項參數中.

Note that this is almost identical to this demo, except for the requirement for the user to type "@". That code is located inside the source option argument.

希望對您有所幫助.

這篇關于實現 jquery UI 自動完成以在您鍵入“@"時顯示建議的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 色偷偷人人澡人人爽人人模 | 亚洲精品久久嫩草网站秘色 | 日本一二三区在线观看 | 国产一伦一伦一伦 | 欧美精品一二三 | 国产综合第一页 | 三级免费网| 精精国产xxxx视频在线播放 | 天堂亚洲| 久久久美女 | 国产精品一区二区久久 | 久久天天躁狠狠躁夜夜躁2014 | 99精品国产一区二区青青牛奶 | 九九热这里 | 亚洲免费视频在线观看 | 欧美影院 | 五月综合久久 | 中文字幕加勒比 | 亚洲一区二区久久 | 色婷婷精品久久二区二区蜜臂av | 日韩中文字幕免费 | 日本三级网站在线观看 | 一级a性色生活片久久毛片 一级特黄a大片 | 国产伦精品一区二区三区精品视频 | 久久成人精品视频 | 亚洲三级免费看 | 一级看片免费视频 | 999久久久久久久久6666 | 日韩靠逼 | 日韩精品一区二区三区中文字幕 | 人人干人人爽 | 国产精品久久久久久久午夜片 | 久久久久亚洲精品 | 国产网站在线免费观看 | 日韩欧美字幕 | 欧美午夜精品 | 亚洲电影免费 | 九九久久这里只有精品 | 中文字幕av一区二区三区 | 亚洲精品毛片av | 国产免费自拍 |