像AutoSuggest这样的JQuery Facebook,由"@"触发 [英] JQuery Facebook like AutoSuggest triggered by "@"

查看:51
本文介绍了像AutoSuggest这样的JQuery Facebook,由"@"触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a JQuery (or other framework) plugin, kind of working like the Facebook status message text box.

它应该做什么:

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

  • Allow text to be typed freely without triggering the AutoSuggest (as opposed to normal AutoSuggest boxes)

在由某个字符(例如"@")触发时显示自动建议.

Show the AutoSuggest, when triggered by a certain character, such as '@'.

实际上,它的工作方式应与FaceBook中的工作方式完全相同...:)

Actually, it should work exactly like the one in FaceBook ... :)

推荐答案

我将使用以下内容: http://www.codeproject.com/KB/aspnet/Search_SuggestTextBox.aspx

I would use something like this: http://www.codeproject.com/KB/aspnet/Search_SuggestTextBox.aspx

该库的优点是它是由文本输入的 onkeyup 触发的.这意味着您可以更改其提供的JS函数以检查正确的按键顺序

The good thing about this library is that it is triggered by the text input's onkeyup. This means you can alter their provided JS function to check for the correct key sequence

也许是这样的:

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; 
    }  
}

这篇关于像AutoSuggest这样的JQuery Facebook,由"@"触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆