<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">{margin:0px auto; padding:0px} #xianshi {width:300px; margin-top:20px} #txt {width:300px} #name {width:296px} #list {width:300x; position:absolute; z-index:3;}. sj{width:298px; height:19px; border:1px solid #0FF; border-top:0px; background-color: #FFF;}. sj:hover{Cursor:pointer} #fg {margin:30px 0px 20px 0px;}</style>$ (document). Ready (function(e) {Xianshi (); //input content Display dropdown$ ("#name"). KeyUp (function(){ varkey=$ ( This). Val (); $.ajax ({async:false, URL:"Ajax5chuli.php", Data:{key:key,bs:0}, type:"POST", DataType:"TEXT", Success:function(data) {if(Data.trim () = = "") { $("#list"). HTML (""); } Else { varShuju=data.trim (). Split ("|"); varStr= ""; for(vari=0;i<shuju.length;i++) {Shuju[i]; STR=str+ "<div class= ' sj ' >" +shuju[i]+ "</div>" } $("#list"). html (str); $(". SJ"). CSS ("Display", "block"); } } }) //mouse on display background color$ (". SJ"). MouseOver (function(){ $(". SJ"). CSS ("Background-color", "#FFF"); $( This). CSS ("Background-color", "#0F0"); }); //mouse away remove background color$ (". SJ"). Mouseout (function(){ $( This). CSS ("Background-color", "#FFF"); }); //Click to place the value of the selected item in the text box$ (". SJ"). Click (function(){ vartxt=$ ( This). text (); $("#name"). val (TXT); $(". SJ"). CSS ("display", "none"); Xianshi (); }) Xianshi (); }) });//querying all data display tablesfunctionXianshi () {varkey=$ ("#name"). Val (); $.ajax ({URL:"Ajax5chuli.php", Data:{key:key,bs:1}, type:"POST", DataType:"TEXT", Success:function(data) {varHang=data.trim (). Split ("|"); varstr= "<tr><td> Car name </td><td> series </td><td> time to market </td><td> fuel consumption </td ><td> Price </td></tr> "; for(vari=0;i) { varLie=hang[i].split ("^"); STR=str+ "<tr><td>" +lie[1]+ "</td><td>" +lie[2]+ "</td><td>" +lie[3]+ "</td> <td> "+lie[4]+" </td><td> "+lie[7]+" </td></tr> "; } $("#tb"). html (str); } })}</script>View Code<?Phpinclude ("Dbda.php"); $db=NewDbda (); $bs=$_post["BS"]; $key=$_post["Key"];if($bs ==1) {$sql= "SELECT * from car where name like '%{$key}% '"; Echo $db-strquery ($sql);}Else { if($key = = "") {echo""; } Else{$sql= "SELECT name from car where name is like '%{$key}% '"; Echo $db-strquery ($sql); };};
View CodeAJAX Search Auto Show Practice