The easiest way to do this is to use the jquery AutoComplete method directly, as shown in the example
In HTML
The code is as follows |
Copy Code |
<script Src= "/js/v2/jquery.input_complete.js" type= "Text/javascript" ></SCRIPT> <link rel= "stylesheet" href = "/css/v2/jquery.input_complete.css" type= "Text/css"/> <script type= "Text/javascript" $ (function () { $ ("#abcc"). Bigautocomplete ({width:176,data:[{title: "The Wharf Century Washington", Result: " 5976898 "},{title:" The Kowloon Cang June seal, Result: "5976896"},{title: "Zhoushan Zhu Jia Tsim Dong Sha Resort", Result: "5976895"},{title: "Guangsha Sky Capital Jazz Garden", Result: " 5976893 "},{title:" Green Green Jade Garden, Result: "5976892"},{title: "Jiangnan Ming Lou", Result: "5976890"},{title: "Shimao Riverside Garden", Result: "14869"}], Callback:function (data) { $ ("#s_loupan"). Val (data.result); &NBSP }}); }) </script> <input type= "text" id= "ABCC" class= "Sel_quy" autocomplete= "off"/> |
The purpose of this article is to search for a heading with the letter T first letter, instead of the first letter of the second text.
For example the Orbolg, when the T is not shown, press O when the display.
Here is the implementation code. I'm all dizzy myself. Testing is no problem.
The code is as follows |
Copy Code |
Public Function Gwquery () { if ($_post) { $ZM = $_post[' data ']; $WZM = $zm. " %"; $b = M (' WPINDEXGW '); if ($zm!= "T") {//Get the first letter is not T $list 1 = $b->where ("Gwstatus=1 and gwname like '% $ZM%")->order ("Time desc")->select ();//Query $narr =array (); foreach ($list 1 as $key => $val) { $CT 2 = Explode ("", $val [' gwname ']);//Get header split into an array. $szm =strtolower (substr ($ct 2[1],0,1)); Get first letter and lowercase if ($ct 2[0]== "the" && $szm = = $zm) {//If the first character is the and the second letter and the first letter are the same, the case is case-sensitive here. $narr [] = $val; Write array } } }else{//processing the first letter is T, do not want the first word number the display in the list. $list 1 = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select (); foreach ($list 1 as $key => $val) { $CT 2 = Explode ("", $val [' gwname ']); if ($ct 2[0]== "the") { $unnarr [] = $key;//Get the array label of the content that you want to remove. }
}
} $list = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select ();//Normal query. if ($zm = = "T") {//processing when the first letter is T, remove the contents of the above query, that is, if it is the time to press T does not show. foreach ($unnarr as $uval) { Unset ($list [$uval]); } When}else{//is not pressing T, add the second first letter to the array of normal queries. if (!empty ($narr) &&!empty ($list)) {//Take the same condition as normal itself is not empty. $list = Array_merge ($narr, $list);//merge array. }else if (empty ($list)) {//Normal query is empty. To see if there are any with the beginning, then merge $list =array (); $list = Array_merge ($narr, $list); } } if ($list) { $this->ajaxreturn ($list, ' success ', 1); }else{ $this->error ("Bestiary not Found."); } }
} |
Compared to the previous code: too Much Difference
The code is as follows |
Copy Code |
Public Function Gwquery1 () {//before backup. if ($_post) { $ZM = $_post[' data ']; $WZM = $zm. " %"; $b = M (' WPINDEXGW '); $list = $b->where ("Gwstatus=1 and gwname like ' $wzm '")->order ("Time desc")->select (); Dump ($list); if ($list) { $this->ajaxreturn ($list, ' success ', 1); }else{ $this->error ("Bestiary not Found."); } }
} |