I need to use the auto-prompt function in my work. Haha, I am a js novice, so I searched on Baidu and found a .net version of the auto-complete function developed with jquery and its plug-in autocomplete, so I downloaded it and changed it to the php version. , and added functions such as support for selecting text up/down, put it up and share it, it is purely physical work. . . :)
1. Download the jquery library, URL: http://jquery.com/;
2. Download the jquery autocomplete plug-in or directly use the file provided in my attachment. The downloaded file needs to be modified. In order to support up/down selection of text and solve Chinese garbled characters, the problem of solving Chinese garbled characters has been mentioned online, which is to change the encodeURI in the file to escape, and change the keydown to keyup. As for supporting up/downward Please refer to the attachment to select the text below;
3. The following is the calling code:
auto.html content:
getindex.php
header("ContentType:text/plain;charset:gb2312");
define('SCRIPTNAV', 'getindex');
require_once './include/common.inc.php';
$keyWord=iconv('utf-8', 'gb2312', js_unescape($q));
$query = $db-> ;query("SELECT DISTINCT(shopname) FROM {$dbpre}shops WHERE shopname LIKE '%$keyWord%' GROUP BY shopname ORDER BY addtime DESC LIMIT 0,10");
if($query)
{
while ($result = $db->fetch_array($query))
{
echo $result['shopname']."n";
}
}
//Convert the data submitted by js escape
function js_unescape($str)
{
$ret = '';
$len = strlen($str);
for ($i = 0; $i < $len; $i )
{
if ($str[$i] == '%' && $str[$i 1] == 'u')
{
$val = hexdec(substr($str, $i 2, 4));
if ($val < 0x7f) $ret .= chr($val);
else if($val < 0x800) $ret .= chr(0xc0|($val>>6)).chr(0x80|($val&0x3f));
else $ret .= chr(0xe0|($val>> 12)).chr(0x80|(($val>>6)&0x3f)).chr(0x80|($val&0x3f));
$i = 5;
}
else if ($ str[$i] == '%')
{
$ret .= urldecode(substr($str, $i, 3));
$i = 2;
}
else $ret .= $str[$i];
}
return $ret;
}
?>
The attachment is as follows:
http://xiazai.jb51.net/200912/yuanma/jquery_autocomplete_php.rar