我有与这个问题完全相同的问题:
自动建议php ajax有两个输入框不能使用给定的示例代码
然而,在尝试建议时,我仍然有同样的问题.
我有两个输入框,我想从db中自动建议.
然而,自动建议只出现在其中一个框下方,无论输入哪个字段.
这是我在最高层链接的问题中的建议后最终得到的结果.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
function suggest(inputString){
if(inputString.length == 0) {
$('#suggestions').fadeOut();
} else {
$('#customer').addClass('load');
$.post("/templates/autosuggest/autosuggest.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').fadeIn();
$('#suggestionsList').html(data);
$('#customer').removeClass('load');
}
});
}
}
function fill(thisValue) {
$('#customer').val(thisValue);
setTimeout("$('#suggestions').fadeOut();", 10);
}
</script>
<script>
function suggest(inputString){
if(inputString.length == 0) {
$('#suggestionssearch').fadeOut();
} else {
$('#customersearch').addClass('load');
$.post("/templates/autosuggest/autosuggest.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestionssearch').fadeIn();
$('#suggestionsListsearch').html(data);
$('#customersearch').removeClass('load');
}
});
}
}
function fill(thisValue) {
$('#customersearch').val(thisValue);
setTimeout("$('#suggestionssearch').fadeOut();", 10);
}
</script>
Run Code Online (Sandbox Code Playgroud)
我的意见:
<input …Run Code Online (Sandbox Code Playgroud)