[英]Autocomplete focus doesn't work correctly
I have an autocomplete input box. 我有一个自动完成输入框。 I want to display "x" link when I start to write something into input box. 当我开始在输入框中写入内容时,我想显示“ x”链接。 But it doesn't work. 但这是行不通的。 I don't know what is the mistake. 我不知道怎么了。 Here are my codes and jsfiddle below. 这是我的代码和下面的jsfiddle。
http://jsfiddle.net/2mu2ht7g/ http://jsfiddle.net/2mu2ht7g/
<style>
.icon-removeSearchItem{
position: absolute;
margin-left: -16px;
display:none;
}
</style>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"Ruby",
"Scala",
"Scheme"
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
<script>
$( document ).ready(function() {
$('input').focus(function(){
if(this.value==this.defaultValue)this.value='';
var value = $(this).val();
if($('input').val().trim().length > 0 && value != "Add Comment"){
$(".icon-removeSearchItem").show();
}
});
});
</script>
您的问题尚不清楚。如果您说要显示搜索值的限制数量,则可以使用以下代码:-$(“ #search”).autocomplete({来源:tags.slice(0,limit ),
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.