我用codeigniter在我的网站上做自动完成系统。但我有问题。我可以在 Chrome 中做到这一点,但在 mozilla 和 IE 中不起作用。例如,在chrome中打开下拉列表中查询的结果项,mozilla和IE出现“2 results are available, use up and down arrow keys to navigate”。验证屏幕截图
视图(autoComplete_v.php):
<head>
<link href="../../css/ui-lightness/jquery-ui-1.10.3.custom.css" media="screen" type="text/stylesheet" rel="stylesheet" />
</head>
<body>
<form>
<label for="search">Search</label>
<input id="search" type="text"/>
<input id="hiddenurl" type="hidden">
<input type="submit" value="submit"/>
</form>
<script src="<?php base_url();?>../../js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="<?php base_url();?>../../js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
<script src="<?php base_url();?>../../js/autocomplete.js" type="text/javascript"></script>
js 文件(autocomplete.js):
$(document).ready(function(){
$('#search').keypress(function(e){
if(e.which == 13)
{
e.preventDefault();
}
var searched = $('#search').val()
var fullurl = $('#hiddenurl').val() + '../autoComplete_c/getResult/' + searched
$.getJSON(fullurl,function(result){
//display suggestion code goes here
var elements = [];
$.each(result, function(i, val){
elements.push(val.referencia)
})
$('#search').autocomplete({
source : elements
})
})
});
});
控制器(autoComplete_c.php):
public function getResult($referencia){
if(!empty($referencia) || isset($referencia))
{
$this->db->select('referencia');
$this->db->like('referencia', $referencia);
echo json_encode( $this->db->get('produto_servico_tbl')->result());
}
}
铬合金:
Mozilla 和 IE: