废话不多少直接上代码
后台部分:
$keyword = iconv( 'UTF-8', 'gb2312//IGNORE' , $_GET['keyword']);
$str = "select `prj_id`,`prj_itemname` from ".D_BASE."project where `prj_city` = ".CITYID." and `prj_disp` = 1 and `prj_itemname` like '%".$keyword."%'";
$rs = $this->db->Execute($str);
$rows=$rs->GetAll();
$re = json_encode(g2u($rows));
echo $re;
exit();
前台部分:
<script type="text/javascript" src="images/jquery-ui/core.js"></script>
<script type="text/javascript" src="images/jquery-ui/widget.js"></script>
<script type="text/javascript" src="images/jquery-ui/position.js"></script>
<script type="text/javascript" src="images/jquery-ui/menu.js"></script>
<script type="text/javascript" src="images/jquery-ui/autocomplete.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script >
$(document).ready(function(){
//缓存
var cache = {};
$.ajaxSettings.contentType = "application/x-www-form-urlencoded;charset=UTF-8";
$( "#keyword" ).autocomplete({
minLength: 1,
max:20,
source: function(request, response ) {
var term = request.term;
var oldCity = $("#city").val();
if (( term in cache ) && (oldCity in cache)) {
response( $.map( cache[ term ], function( item ) {
return {
label:item.prj_itemname,
prj_id:item.prj_id
}
}));
return;
}
$.ajax({
url: "./main.php",
dataType: "json",
data:{
'keyword': request.term,
'limit':20,
'module':'api_activity_recommend',
'act':'api',
'action':'getLoupanList'
},
//async:false,
success: function( data ) {
cache[ term ] = data;
response( $.map( data, function( item ) {
if(item.prj_id>0){
return {
label:item.prj_itemname,
prj_id:item.prj_id,
limit:20
}
}
}));
}
});
},
select: function( event, ui ) {
$("#prj_id").val(ui.item.prj_id);
$('#keyword').val(ui.item.prj_itemname);
}
}).change(function(){
$("#prj_id").val('');
$('#keyword').val('');
});
});
</script>
<div class="title panel-body">
<ol class="breadcrumb">
<li>{$title}</li>
<li>{CITY_NAME}</li>
</ol>
</div>
<div class="search panel-body">
<form action="./main.php" method="get" class="form-horizontal">
<div class="form-group">
<label for="keyword" class="col-sm-1 control-label">
项目推广名:
</label>
<div class="col-sm-3">
<input class="form-control" name="keyword" id="keyword" value="{$keyword}" placeholder="请输入项目推广名称" size="38">
<input type="hidden" name="prj_id" id="prj_id" value="{$prj_id}" />
</div>
<div class="form-group col-sm-3">
<select class="form-control" name="channel" id="channel">
<option>请选择物业类型</option>
{loop $channel_desc $key $vo}
<option value="{$key}" {if ($key == $search_channel)}selected{/if}>$vo</option>
{/loop}
</select>
</div>
<input type="hidden" name="module" value="pro_jiucuo">
<button type="submit" class="btn btm-primary">搜索</button>
</div>
</form>
</div>
<div class="panel-body">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th width="60">prj_id</th>
<th>项目名称</th>
<th width="120">物业类型</th>
<th width="120">纠错人手机</th>
<th>提交时间</th>
<th width="120">操作</th>
</tr>
</thead>
<tbody>
{loop $jiucuos $key $vo}
<tr {if ($key%2==1)}class="info"{/if}>
<td scope="row">{$vo['prj_id']}</td>
<td>{$vo['itemname']}</td>
<td>{$channel_desc[$vo['channel']]}</td>
<td>$vo['phone']</td>
<td>{$vo['created']}</td>
<td>
<a href="./main.php?module=pro_jiucuo&act=edit&id={$vo['id']}" title="查看" data-toggle="modal" data-target="#myModal">
<i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
</a>
</td>
</tr>
{/loop}
</tbody>
</table>
{$page_str}
</div>