我对 jquery 真的很陌生。好吧,我有两个输入文本字段,并且我设法通过以下功能在两个输入字段上附加了自动建议列表
function lookup(inputString,tableName,colName,divId,listId) {
if(inputString.length == 0) {
// Hide the suggestion box.
$(divId).hide();
} else {
$.post("customers.php", {queryString: ""+inputString+"",table:""+tableName+"",col:""+colName+""}, function(data){
if(data.length >0) {
$(divId).show();
$(listId).html(data);
}
});
}
} // lookup
我的表格看起来像这样
<div>
<form>
<div>
Location
<br />
<input type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value,'countries','value','#suggestions','#autoSuggestionsList');" onblur="fillValues(this.value,'#inputString','#suggestions');" autocomplete="off"/>
</div>
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="http://localhost/ci/css/images/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList" >
</div>
</div>
<div>
Favourite Product
<br />
<input type="text" size="30" value="" id="inputString1" onkeyup="lookup(this.value,'product','value','#suggestions1','#autoSuggestionsList1');"
"fillValues(this.value,'#inputString1','#suggestions1');" autocomplete="off"/>
</div>
<div class="suggestionsBox" id="suggestions1" style="display: none;">
<img src="http://localhost/ci/css/images/upArrow.png" style="position: relative; top: -12px;left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList1" >
</div>
</div>
</form>
</div>
和 fillValues 函数看起来像这样
function fillValues(thisVal,inputId,divId)
{
$(inputId).val(thisValue);
setTimeout("$("+divId+").hide();",200)
}
现在,当用户单击列表上的一个值时,输入文本字段应该填充该值。但是我无法这样做。我错过了什么?
ps自动建议列表已成功显示,我的customers.php工作正常。