Jquery autosuggestion继续用Case搜索

时间:2012-12-03 03:49:39

标签: php javascript jquery html

我有一个jquery搜索建议。该功能运行正常。但现在我想要功能检测继续搜索。

示例:我想搜索名称David,我在文本框中输入文本:Da。并将显示名称建议。现在,如果我点击每个地方,div框建议会关闭吗? 在这里我想要什么,当我再次回到点击文本框搜索时,它将显示div框建议最后我输入像案例:Da

到目前为止,这是JS代码:

$(document).ready(function() {
    $(".searchs").keyup(function() {
        var searchbox = $(this).val();
        var dataString = 'searchword=' + searchbox;
        if (searchbox == '') {
            $("#display").hide();
        } else {
            $.ajax({
                type: "POST",
                url: "searchs.php",
                data: dataString,
                cache: false,
                success: function(html) {
                    $("#display").html(html).show();
                }
            });
        }
        return false;
    });
    $(".searchs").blur(function() {
        $("#display").hide();
    });
});

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

如果文本框中有文本,用户在文本框中单击时,如何显示建议div。

$(".searchs").focus(function()
{
  var seachbox = $(this).val(); /*note, you will need to change $(this) to the proper selector of your textbox*/
  if(seachbox != '')
  {
    $("#display").show();
  }
});