光线cms,如何增加像百度一样的智能提示
![](https://images.cnblogs.com/cnblogs_com/kmoon/auto1.png)
很有ajax效果吧,呵呵!
先上图呵呵:
要看实际 效果 到我的小站吧,苍老师电影,哈哈 ! http://www.fur168.com/
苍井空在线_苍井空迅雷
我把过程整了一下,如下:
在header 增加js 前台调用
jQuery(document).ready(function() {
jQuery("#wd").autocomplete(
"ajax.php",
{
max: 6,
scroll: false,
width: 162 ,
dataType: 'json',
parse: function(data) {
var parsed = [];
for (var i = 0; i < data.length; i++) {
parsed[parsed.length] = {
data: data,
value: data ,
result: data
};
}
return parsed;
}
}
);
})
光线用的thinkphp 框架开发的,我没有看过,也不想了解他了,反正功能需求简单,就自己写了,直接操作mysql的,
后台代码 :
< ?php
header("Content-Type:text/html;charset:utf-8");
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='fur168.com';
$mysql_database='fur168.com';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
//echo unescape($_GET['q']);
$sql = "select * from gx_video where title like '%".$_GET['q']."%'";
//echo $sql;
//$sql='select title from gx_video';
mysql_select_db($mysql_database,$conn);
mysql_query("SET NAMES UTF8");
$result=mysql_query($sql);
$array=array();
while($row = mysql_fetch_array($result))
{
array_push($array,array($row['title']));
// $row['title'].',';
}
echo JSON($array);
mysql_close($conn);
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,-4)),"gb2312","UCS-2");
elseif(substr($v,0,3) == "&#x")
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,3,-1)),"gb2312","UCS-2");
elseif(substr($v,0,2) == "&#") {
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,2,-1)),"gb2312","UCS-2");
}
}
return join("",$ar);
}
function arrayRecursive(&$array, $function, $apply_to_keys_also = false)
{
static $recursive_counter = 0;
if (++$recursive_counter > 1000) {
die('possible deep recursion attack');
}
foreach ($array as $key => $value) {
if (is_array($value)) {
arrayRecursive($array[$key], $function, $apply_to_keys_also);
} else {
$array[$key] = $function($value);
}
if ($apply_to_keys_also && is_string($key)) {
$new_key = $function($key);
if ($new_key != $key) {
$array[$new_key] = $array[$key];
unset($array[$key]);
}
}
}
$recursive_counter--;
}
function JSON($array) {
arrayRecursive($array, 'urlencode', true);
$json = json_encode($array);
return urldecode($json);
}
?>
其中几个函数 是php 和ajax之间的中文编码 转换,功能 。另外几个js文件自己google一下,下载!
大家有啥好的功能也共享一下吧,或者给哥加个链接,