久久久久久久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 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 欧美一级高潮片免费的 | 在线观看中文字幕 | 亚洲www| 中文字幕在线中文 | 九九热在线免费视频 | 在线视频中文字幕 | 色综合99 | 久久国产精品视频 | 久久不射网 | 91精品国产91久久久久久密臀 | 亚洲一区二区视频在线播放 | 在线观看成人小视频 | 欧美精品成人一区二区三区四区 | 久久国产精品久久久久久 | 日韩在线资源 | 成人做爰www免费看视频网站 | 日韩在线视频观看 | 国产日韩欧美一区二区 | 欧美午夜精品 | 国精日本亚洲欧州国产中文久久 | av网址在线 | 亚洲欧美视频一区二区 | 91亚洲欧美 | 狠狠色网| 91久久精品一区二区二区 | 91在线视频网址 | 国产精品视频久久 | 国产精品日韩欧美一区二区 | 亚洲国产成人精品久久 | 欧美日韩精品一区二区 | 国产精品精品视频一区二区三区 | 欧美精品欧美精品系列 | 久久精品国产一区二区三区不卡 | 欧美视频一区二区三区 | 成人欧美一区二区三区在线观看 | 国产精品亚洲视频 | 久久久久久久夜 | 亚洲激情av | 国产美女在线观看 | 国产一区久久久 | 亚洲一级淫片 |