2011-12-12 70 views
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">&nbsp;</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> 
+0

中的代码不能(并且不)做你的描述。请提供更完整的代码示例,其中包括实际更新输入框的部分。 FWIW,你的'$(this).val();'目前什么都不做。 –

+0

我已经编辑了自动列表的关键事件。希望它会有所帮助 –

回答

0

两件事情正在进行这里 -

  1. 我不知道你捕捉你想捕捉的事件。我无法确定用例是什么,但您似乎在说您正在倾听点击某个建议。但是,您并未在建议框的任何位置捕获任何点击。

  2. 模糊事件只隐藏.suggestionsBox,如果这就是它的意思,那么它工作的很好! $(this).val();行没有做任何有用的事情。 JavaScript实际上找到了这个价值,但它没有对它做任何事情。

无论如何,我没有看到输入框被空白。

这是一个使用测试回声阿贾克斯小提琴:http://jsfiddle.net/xXF9v/