Em projetos reais, podemos alterar a aquisição de dados para aquisição dinâmica do AJAX, no getContent ()
<! Doctype> <html> <head> <title> js/jQuery se refere semelhante à função de pesquisa do Baidu </ititle> <meta name = "Author" content = "Michael"> <meta name = "Palavras -chave" content = "js/jQuery realizarem -se similar à função de Baidu"> <meta "" descrição "" Reaccent = JS/ teclado "> <meta http-equiv =" content-type "content =" text/html; type = "texto/css">#contêiner {posição: absoluto; esquerda: 50%; topo: 40%;}#Content {float: esquerda; posição: relativa; direita: 50%;} entrada {borda: 0; largura: 288px; altura: 30px; font-size: 16px; padding: 0px; line-hight; Pointer;}. addbg {Background: #87A900;}. Primeiro {borda: sólido #87A900 2px; largura: 300px;} #Anexar {borda: sólido #87A900 2PX; Border-top: 0; Display: None; id = "kw" onkeyup = "getContent (this);" /></div><div id="append"></div></div><script type="text/javascript">var data = ["Hello, I am Michael","Who are you","You are the best","You are the most precious","You are my best friend","You are my best friend","You are fool","You understand","You are fascinated by me","You are my olhos "]; $ (document) .ready (function () {$ (document) .Keydown (function (e) {e = e || window.event; var keycode = e.which? E.which: e.KeyCode; if (keycode == 38) {if (jQuery.Trim ($ ("#append "). (keycode == 40) {if (jQuery.trim ($ ("#append"). html ()) == "") {return;} $ ("#kw"). bluur (); if ($ ("item"). hasclass ("addbg") {motenext ();} {$ (". Item"). RemoveClass ('addbg'). Eq (0) .addclass ('addbg');}} else if (keycode == 13) {dojob ();}}}); var mOvePrev = function) {$ ("#kw). == 0) {$ (". Item"). RemoveClass ('addbg'). Eq ($ (". Item"). Length - 1) .addclass ('addbg');} else {$ (". $ (". addbg"). preall (). comprimento; if (index == $ (". item"). comprimento - 1) {$ (". item"). removeclass ('addbg'). eq (0) .addclass ('addbg');} else {$ (". item). 1. jQuery.Trim ($ (obj) .val ()); if (kw == "") {$ ("#append"). hide (). html (""); return false;} var html = ""; para (var i = 0; i <data.length; i ++) {if (data [i]. class = 'item' onMouseEnter = 'getFocus (this)' onclick = 'getCon (this);'> " + dados [i] +" </div> "}} if (html! getfocus (obj) {$ (". item"). removeclass ("addbg"); $ (obj) .addclass ("addbg");} função getCon (obj) {var value = $ (obj) .text (); $ ("#kw")O exposto acima é o prompt de correspondência difuso para a caixa suspensa Automática da Imitação do JS Baidu introduzida pelo editor. Espero que seja útil para todos. Se você tiver alguma dúvida, deixe -me uma mensagem. O editor responderá a todos a tempo!