ajax实时查库,实现输入框的自动完成提示框功能
来源:互联网 发布:软件运营维护方案 编辑:程序博客网 时间:2024/05/01 03:44
html:
<table>
<tr>
<td>
输入项
</td>
<td>
<input type="text" name="input_data" id="input_data" value="" autocomplete="off" onkeyup="show_list('search_data');" onblur="hide_sugg()" />
<div class="suggestions_box" id="suggestions" style="display: none;">
<div class="suggestion_list" id="auto_suggestions_list"></div>
</div>
</td>
</tr>
</table>
js:
function show_list(url) {
var input_data = $("#input_data").val();
if(input_data == "" || input_data == null){
return null;
} else {
$.ajax( {
type : "post",
url : "/" + url,
data : "input_data=" + input_data,
dataType : 'json',
success : function(res) {
if (res.length > 0) {
$('#suggestions').show();
$("#auto_suggestions_list").html("");
for (i = 0; i < res.length; i++) {
var span_dom = $('<li onClick="fill('+"\'"+res[i]+"\'"+')"/>').text(res[i]);
$('#auto_suggestions_list').append(span_dom);
}
} else {
$("#auto_suggestions_list").html("");
$('#suggestions').hide();
}
}
});
}
}
function fill(value) {
$("#input_data").val(value);
$("#input_data").focus();
setTimeout("$('#suggestions').hide();", 200);
}
function hide_sugg() {
$("body").not("#suggestions").not("#auto_suggestions_list").not("#auto_suggestions_list li").click(function(){
setTimeout("$('#suggestions').hide();", 200);
});
$("body").keyup(function(event){
var key = event.which;
if (key == 9 || key == 13){
setTimeout("$('#suggestions').hide();", 200);
}
});
}
后台php:
public function search_data(){
...
echo json_encode($data);
}
css:
.suggestions_box {
position: relative;
width: 230px;
z-index: 998;
}
.suggestion_list {
background: none repeat scroll 0 0 white;
border: 1px solid #B8CFDB;
position: absolute;
width: 230px;
z-index: 999;
height: expression( this.scrollHeight > 200 ? "200px" : "auto" );
max-height: 200px;
overflow-y: auto;
}
.suggestion_list li{
padding: 3px;
cursor: default;
list-style-type :none;
}
.suggestion_list li:hover {
background-color: #EEEEEE;
}
- ajax实时查库,实现输入框的自动完成提示框功能
- jQuery中使用Ajax实现文本输入框的自动完成功能
- jQuery+PHP+Mysql实现输入自动完成提示的功能
- jQuery+PHP+Mysql实现输入自动完成提示的功能
- jQuery+PHP+Mysql实现输入自动完成提示的功能
- AJAX实现文本框输入自动提示功能
- AutoCompleteTextView (自动完成输入框自动提示功能的菜单)
- js实现输入框自动提示功能
- Android——自动完成输入框提示功能的菜单_AutoCompleteTextView
- java完成输入框的自动完成功能
- Ajax实现文本框的自动完成功能
- Ajax搜索框的自动提示功能
- AJAX 实现自动完成功能
- ajax自动完成 下拉提示框的疑问
- 基于jquery实现的类似百度搜索的输入框自动完成功能
- 基于jquery实现的类似百度搜索的输入框自动完成功能
- 基于jquery实现的类似百度搜索的输入框自动完成功能
- Delphi编辑框自动提示完成功能
- 使用PHP实现计算两个日期间隔的年、月、周、日数
- 关于$_SERVER()
- 开源:给每个文档计算一个指纹,然后用指纹进行相似度的计算 含源码和可执行程序
- 让 IIS Express 支持 PHP
- apache/nginx access.log 说明
- ajax实时查库,实现输入框的自动完成提示框功能
- 当高速的cpu遇上低速的内存怎么办?
- poj 2418
- cocos2d 中添加显示文字的三种方式
- js使用技巧
- android Adapter综合使用(ArrayAdapter、SimpleAdapter、BaseAdapter在ListView和GridView中的使用)
- 在Eclipse中导入JavaDoc
- HOJ 1001 A+B
- Android开发入门之环境概念介绍