开发者

Jquery autocomplete only when hotkey is present

Hi i want to bring back some product and usernames, however they should only comeback when they "@" symbol has been typed first, how do i go about doing this?

Hi i managed to come up with this,

<script type="text/javascript">
    $(function () {
                $(".fateinp").autocomplete({
                    source: function (request, response) {
                        $.ajax({
                            url: "WebServices/List.asmx/FetchUsers",
                            data: "{ 'product': '" + request.term + "' }",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            dataFilter: function (data) { return data; },
                            success: function (data) {
                                response($.map(data.d, function (item) {
                                    return {
                                        value: item._Name
                                    }
                                }))
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
          开发者_JS百科                      alert(textStatus);
                            }
                        });
                    },
                    minLength: 2
                });
    });
</script>

However whenever i add your suggestion;

var autocompleter = document.getElementById("some-element");

I keep getting autocompleter is null, forgive me if this is a novice question. Thanks


Wrap the call to AJAX for autocompleting (or displaying if they've already been cached) using something like this.

var autocompleter = document.getElementById("some-element");

if (autocompleter.value.startsWith("@")) {
  // invoke AJAX here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜