我正在寻找一个JQuery(或其他框架)插件,类似于Facebook状态消息文本框。
应该做什么:
允许自由输入文字而不触发AutoSuggest(与普通的AutoSuggest框相对)
显示AutoSuggest,由某个字符触发,例如'@'。
实际上,它应该与FaceBook中的那个完全一样......:)
答案 0 :(得分: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;
}
}
答案 1 :(得分: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