1

我正在寻找一个 JQuery(或其他框架)插件,有点像 Facebook 状态消息文本框。

它应该做什么:

  • 允许在不触发 AutoSuggest 的情况下自由输入文本(与普通 AutoSuggest 框相反)

  • 当某个字符(例如“@”)触发时,显示 AutoSuggest。

实际上,它应该与 Facebook 中的完全一样...... :)

4

2 回答 2

1

我会使用这样的东西:http: //www.codeproject.com/KB/aspnet/Search_SuggestTextBox.aspx

这个库的好处是它是由文本输入的onkeyup触发的。这意味着您可以更改他们提供的 JS 函数以检查正确的键序列

也许是这样的:

var shiftDown=false; //Track if SHIFT was the last key pressed.

function searchSuggest(e) 
{
    var key = window.event ? e.keyCode : e.which;

    if (key==40 || key==38)
    {
        shiftDown=false;
        scrolldiv(key); 
    }
    else if (key == 16) // SHIFT WAS PRESSED
    {
        shiftDown=true;
    }
    else if (key == 50 && shiftDown) // 2 WAS PRESSED
    {
        if (searchReq.readyState == 4 || searchReq.readyState == 0) 
        {
            var str = escape(document.getElementById('txtSearch').value);
            strOriginal=str;
            searchReq.open("GET", 'Result.aspx?search=' + str, true);  
            searchReq.onreadystatechange = handleSearchSuggest;
            searchReq.send(null);
            shiftDown=false; 
        }
    }  
    else 
    {   
        shiftDown=false; 
    }  
}
于 2010-09-21T20:51:46.887 回答
0

希望现在您(OP)已经能够利用 Dutchie432 的答案来创建您满意的解决方案。但是,如果您或其他任何碰巧偶然发现此问题的人,还没有,或者有并且可能正在寻找一个强大的、即用型的解决方案……

...看起来Mentionator正是您正在寻找的:它是一个 jQuery 插件,它使客户端能够创建对文本区域中预定义实体的突出显示的引用(“提及”)。它是由这个人在这里维护的:)。

与类似的插件不同,Mentionator 提供了以下选项,这些选项提供了根据您的要求使其能够完全像 Facebook 的标记工具一样运行的选项:

doesRecognizeDelimitedSubstrings: 
    A boolean which, if defined as true, will allow the external value
    of a mention, herein called "mentionExternalValue", to sustain
    modifications so long as the result of each such modification 
    is in mentionExternalValue.split(delimValue)

delimValue: 
    A string, or regular expression representing the set of strings,
    that, given doesRecognizeDelimitedSubstrings === true, delimit
    mentionExternalValue substrings that can also serve as external
    value of the mention if yielded by a modification of
    mentionExternalValue
于 2016-07-03T00:27:40.897 回答