我真正的新jquery.Well我有两个输入文本字段,我已经成功地通过了以下功能如何使用jquery populate输入文本字段?
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
到attatch同时在输入字段列表自我暗示和我的形式看起来像这样
<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)
}
现在,当用户点击一个值列表中输入文本上字段应该填充该值,但我无法这样做。我错过了什么?
p.s. autosuggestion列表已成功显示,我的customers.php工作正常。
通过jquery使用它的id来定位一个元素,它就像这个$(“#elementID”) – fatiDev 2013-02-26 11:41:21
你也说,当用户点击一个值时,你的代码在哪里?你写的函数将不会被调用,直到你捕获用户点击 – fatiDev 2013-02-26 11:47:20
http://api.jquery.com/click/ – fatiDev 2013-02-26 11:49:32