jquery自动完成在IE11和chrome中显示空搜索框
我正在使用jquery自动完成创建搜索栏 以下是我的自动完成代码:jquery自动完成在IE11和chrome中显示空搜索框,jquery,autocomplete,jquery-autocomplete,Jquery,Autocomplete,Jquery Autocomplete,我正在使用jquery自动完成创建搜索栏 以下是我的自动完成代码: $('#search_bar input#search_box').autocomplete({ source: function( request, response ) { $.ajax({ url: "service/search.php", type: "POST", data: {action:'getSuggest
$('#search_bar input#search_box').autocomplete({
source: function( request, response ) {
$.ajax({
url: "service/search.php",
type: "POST",
data: {action:'getSuggest',categoryId:$('#search_bar #selectSearch').val(),searchText:request.term},
dataType: "json",
cache: false,
success: function( data ) {
response( $.map( data['0'], function( Convalue ) {
return {
label: Convalue['name'],
value: Convalue['name'],
id: Convalue['ID']
}
}));
},
error: function (e,a,b) {
jAlert('error in searching products'+e,'Failed');
}
});
},
cacheLength: 0,
minLength: 1,
select: function( event, ui ) {
event.preventDefault();
$('#search_bar input#search_box').val();
if(ui.item)
{
var categoryId=$('#search_bar #selectSearch').val();
if(categoryId=='0'){
if(ui.item.id=='1')
location.replace('custom-granule.php');
else if(ui.item.id=='2')
location.replace('custom-raw.php');
else
location.replace('product-info.php?id='+ui.item.id);
}
else if(categoryId=='1')
location.replace('product-symptom.php?id='+ui.item.id);
else if(categoryId=='2')
location.replace('product-pattern.php?patternId='+ui.item.id);
else
location.replace('product-category.php?id='+ui.item.id);
}
else {
jAlert("Nothing selected, input was " + this.value);
}
}
});
现在我的问题是:IE和Chrome在搜索时显示警告消息“Searchbox为空”。IE和chrome在显示此警报框时不一致。有时它会出现,有时它不会。FF似乎正常。搜索栏输入搜索框
此带有运算符的选择器可能不是每个浏览器中的“选择正确”元素。您可以通过F12在chrome控制台中测试它,我认为这不是选择器的问题。因为,有时搜索是正确的,如果我重复搜索超过10次,那么它在IE和chrome中显示为“空搜索”。我昨天在mvc项目中看到的行为与我从标记名中删除字符时看到的行为相同,我将uniq id写入元素,这对我有效。我不确定,但试试这个