This paper mainly introduces the real-time search hint function implemented by PHP+JS, which involves the traversal of data and string in real-time with Ajax, and the related operation skill of matching, and the need of friends can be consulted, hoping to help everyone.
As follows:
The code is as follows:
HTML code: (This code is implemented in two ways, a jquery, a native JS)
PHP code is as follows: (PHP can not only consider the use of arrays directly, you can also consider directly querying the database, get the database content, this code uses an array. )
<?php$provinces=array ("Beijing", "Tianjin", "Shanghai", "Chongqing", "Hebei", "Henan", "Heilongjiang", "Jilin", " Changchun ", " Shandong "," Anhui "," Shanxi "," Guangzhou "," Yunnan "," Hainan "," Xizang "," Qinghai "," Fujian "," Guizhou "," Jiangsu "," Zhejiang "," Guangzhou "," Yunan "," Hainan "," Xizang "," Neimenggu "," Sichuan "," Gansu "," Ningxia "," Xianggang "," Aomen "); $tmp =$_get[' Q '); $val =array (); $k =0;if (strlen ($tmp) >0) {for ($i =0; $i <31; $i + +) { if (Strpos ($provinces [$i], $tmp)!==false) { //pass value to Val $val [$k]= $provinces [$i]; Subscript added $k = $k +1; } } Iterate over the Val array for ($j =0; $j <count ($val); $j + +) { echo $val [$j]; echo "<br>"; }}? >