这是我的观看代码
<input type="text" name="chname" id="chrname" placeholder="church name" />
这是我的控制器代码
function auto_comp(){
$q = strtolower($_GET["q"]);
if(!$q) return;
$res=$this->churchmodel->auto_compt($q);
if($res){
foreach($res as $row){
//echo row->chid;echo "<input type=\"text\" value=\"".$row->chid."\" />";echo row->churchname."\n";
}
}
}
这是我的型号代码
function auto_compt($name){
$val="%".$name."%";
$query=$this->db->query("select distinct name as churchname, id as chid from church where name like '$val'");
if($query->num_rows>0){
return $query->result();
}else{
return false;
}
}
jquery代码
$().ready(function() {
$("#chrname").autocomplete("localhost/deeps/genting/index.php/church/auto_comp", {
width: 260,
matchContains: true,
selectFirst: false
});
});
这里它的工作完美,但我需要在特定的选择上获取相应的ID,以便我可以轻松存储所选值的id。请提前帮助谢谢
答案 0 :(得分:0)
$(document).ready(function() {
$("#chrname").autocomplete("localhost/deeps/genting/index.php/church/auto_comp", {
width: 260,
matchContains: true,
selectFirst: false,
select: function (event) {
alert(event.target.id) // fetch your id here
}
});
});