0
從我的特定問題我已經得到了實現自動完成列表的答案..但問題是當我點擊任何建議它空白我的輸入框。我有輸入框類track
。我的功能,我用於在模糊事件是..組文本框的自動完成列表
<input name="track[]" type="text" class="track" maxlength="150"/>
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="images/upArrow.png" style="position: relative; top: -12px; left: 50px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList"> </div>
</div>
<script>
$('input.track').keyup(function() {
var poetname = $(this).val();
if(poetname.length == 0) {
// Hide the suggestion box.
$(this).parent().find('#suggestions').hide();
}
else {
$.ajax({
url: "rpc.php",
type: "post",
data: {queryString: poetname},
context: this, // i.e. the text box
success: function(data) {
if(data.length >0) {
$(this).parent().find('#suggestions').show();
$(this).parent().find('#autoSuggestionsList').html(data);
}
}
});
}
});
$('input.track').blur(function() {
$(this).val();
$(this).parent().find('.suggestionsBox').hide();
});
</script>
中的代碼不能(並且不)做你的描述。請提供更完整的代碼示例,其中包括實際更新輸入框的部分。 FWIW,你的'$(this).val();'目前什麼都不做。 –
我已經編輯了自動列表的關鍵事件。希望它會有所幫助 –