Real-time search prompt function implemented by PHP + JS, phpjs
This example describes the real-time search prompt function implemented by PHP + JS. We will share this with you for your reference. The details are as follows:
As follows:
The Code is as follows:
HTML code: (this code is implemented in two ways, Jquery and native JS)
<Html>
The PHP code is as follows: (PHP can not only directly use arrays, but also directly query the database to obtain database content. This Code uses arrays .)
<? Php $ provinces = array ("beijing", "tianjin", "shanghai", "chongqing", "hebei", "henan", "heilongjiang", "jilin ", "changchun", "shandong", "anhui", "shanxi", "guangzhou", "yunnan", "hainan", "xizang", "qinghai", "fujiian ", "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 the value to val $ val [$ k] = $ provinces [$ I]; // Add $ k = $ k + 1 to the subscript ;}} // traverse the val array for ($ j = 0; $ j <count ($ val); $ j ++) {echo $ val [$ j]; echo "<br>" ;}}?>