In den tatsächlichen Projekten können wir die Datenerfassung in GetContent () in Ajax Dynamic Acquisition ändern, um
<!DOCTYPE><html><head><title>js/jQuery realizes similar to Baidu search function</title><meta name="Author" content="Michael"><meta name="Keywords" content="js/jQuery realizes similar to Baidu search function"><meta name="Description" content="js/jQuery realizes similar to Baidu search function, and can be controlled by Tastatur "> <meta http-äquiv =" content-type "content =" text/html; {Position: absolut; links: 50%; oben: 40%;}#Inhalt {float: links; Position: relativ; rechts: 50%;} Eingabe {Grenze: 0; Breite: 288px; Höhe: 30px; Schriftgröße: 16px; Padding: 0 5px; Line-Height: 30px; #87a900;}. Erstens {Grenze: Solid #87a900 2px; Breite: 300px;} #anhängen {Border: Solid #87a900 2px; Border-top: 0; Anzeige: Keine;} </style> </head> <body> <div id = "container"> < OnKeyUp = "GetContent (this);" /> </div> <div id = "append"> </div> </div> <script type = "text/javaScript"> var data = ["Hallo, ich bin Michael", "Wer bist du", "Du bist der beste", "du bist der kostbarste", "du bist mein bester Freund", "du bist mein bester Freund", du bist "du bist", "du", "du verstehst", ",", "versteht", "," versteht ",", "," versteht "," versteht ",", "," versteht "", "," versteht "," versteht ",", ",", versteht "," versteht "", ",", "versteht" "," versteht "", ",", "versteht", "versteht", ",", "versteht", "," versteht "", ",", versteht "," versteht "", ",", "," versteht "," versteht "", ",", "versteht" "," verstehst Augen "]; $ (Dokument) .Ready (function () {$ (document) .Keydown (Funktion (e) {e = e || window.event; var keycode = e.which? (KeyCode == 40) {if (jQuery.trim ($ ("#append"). {$ (". Item"). == 0) {$ (". Item"). $ (". addbg"). prevall (). Länge; if (index == $ (". item"). Länge - 1) {$ (". Item"). 1) .AddClass ('addbg');}} var dojob = function () {$ ("#kw"). Blur (); var value = $ (". Addbg"). Text (); $ ("#kw"). Val (value); jQuery.trim ($ (obj) .val ()); if (kw == "") {$ ("#append"). hide (). "<div class = 'item' onmouseenter = 'getfocus (this)' onclick = 'getcon (this);'>" + data [i] + "</div>"}} if (html! = "") {$ ("#append"). {$ ("#append"). hide (). html ("");}} Funktion getFocus (obj) {$ (". item"). removeclass ("addbg"); $ (obj) .Text (); $ ("#kw"). Val (Wert); $ ("#append"). hide (). html ("");} </script> </body> </html>Das obige ist die Fuzzy-Matching-Eingabeaufforderung für die vom Editor vorgestellte automatische Dropdown-Box von JS Imitation Baidu. Ich hoffe, es wird für alle hilfreich sein. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht. Der Herausgeber wird alle rechtzeitig antworten!