像“@”触发的JQuery Facebook就像AutoSuggest一样

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

它应该做什么:

  • 允许自由键入文本而不触发AutoSuggest(与普通的AutoSuggest框相对)

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

实际上,它应该像FaceBook中的那个一样…… 🙂

我会用这样的东西: 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; } } 

希望现在你(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