文本自动补全功能确实很实用。
先看下简单的效果:(样式不咋会写)
下面介绍几种:
1:jqery-actocomplete.js
这个网上有个写好的实例,上面挺详细的,可以下来运行下就清楚了就不多做解释
地址:http://download.csdn.net/detail/linlinv3/7744717(如果找不到资源留言找我)
2:jquery-ui.js
jquery-ui.js一般系统中用,所以用这个也比较方便,注意引入包的顺序
<link href="jquery/jquery-ui.css" rel='stylesheet' type="text/css"/>
<script type="text/javasrcipt">jquery/jquery-1.7.1.min.js</script>
<script type="text/javasrcipt">jquery/jquery-ui.js</script>
<input type="text" name="address" width="200" />
<script type="text/javasrcipt">
jQuery(function($)){
$("input[name=address]").autocomplete({
delay: 100, //延长多少秒激活
minLength:1, //最小多少个字符触发
autoFocus:true, //是否选中第一个
source:function(request,response){
var data = new Array();
data.pust("ss");
//......
response(data); //在文本中要提示的数据
}
});
}
</script>
个人比较喜欢用ui的,这个数据动态写入比较方便,可以在var data那写ajax等来去数据啥的。
上面的还可以加改样式
<style>
.ui-autocomplete{
max-height:300px; //显示框最大高度
overflow-y:auto; //竖向滚动条
overflow-x:auto; //横向滚动条
}
html.ui-autocomplete{
height:100px;
}
</style>
例子比较简单个人感觉很实用。可以亲自动手试试,欢迎交流