开发者

How to show autocomplete of a input bar without type?

As you know, <input> has an attribute autocomplete, if it's set to on, it will remember what you type, and when you type again in this input bar, afte开发者_如何学Gor you type a few letter, it will autocomplete the remembered words.

I'd like to know, can I get the autocomplete words without a type?


Do you mean access a browser's autocomplete words from Javascript or similar? Technically no, as this would be a security flaw, and malicious web pages could suck out all of your personal information. In reality there are security flaws in browsers and I've seen IE6, IE7 and Safari are vulnerable to an attack which reveals a browser's autocomplete values.


If you want to set the options for auto complete, you can use jQuery.

    $(document).ready(function() {
  var items = [ {text: "Autocomplete 1"}, 
               {text: "auto 2"}, 
               {text: "auto 3"} ]

$("#list").autocomplete(items, {
  matchContains: true,
  minChars: 0,
  formatItem: function(item) 
    { return item.text; }
    }
  );
  });

and then something like this on the element:

$(".auto_complete").focus(function() { $(this).trigger("keydown") })
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜