搜索框提示相关内容
来源:互联网 发布:淘宝链接转淘客链接 编辑:程序博客网 时间:2024/06/05 22:34
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <style> ul { border: solid #31B0D5 1px; padding-left: 0px; width: 302px; } li { text-align: left; width: 100%; height: 20px; list-style: none; } li:hover { background-color: #BCE8F1; } button { background-color: #3385ff; color: white; border: 0; height: 26px; line-height: 26px; width: 59px; vertical-align: bottom; } </style> <div style="margin-left: 30%;"> <input style="width: 300px;height: 20px;line-height: 20px;vertical-align: bottom;" id="content" type="text" onkeyup="getText()" onfocus="$('#correlate').show()" onblur="$('#correlate').hide()" /> <button onclick="alert($('#content').val())">搜索</button> </div> <div id="correlate" style="margin-left: 30%;margin-top: -17px;"> </div> </body> <script type="text/javascript" src="../js/jquery.min.js"></script> <script type="text/javascript"> //onkeyup在输入框中输入数据时执行 //onblur失去焦点 //onfocus获得焦点 //mouseover //onmouseout var xmlHttp; //获取输入框内容 function getText() { //得到输入框内容 var content = $('#content').val(); // xmlHttp=createXMLHttp(); // var url="search?keyword="+escape(content);//escape解决中文问题 // xmlHttp.open("GET",url,true);//true代表js脚本在send方法后继续执行,不等待服务器的响应 // //xmlHttp状态改变时调用回调方法,状态0-4 // xmlHttp.onreadystatechange=callback; // xmlHttp.send(null); //添加内容前删除上次内容 $('#correlate').empty(); //添加内容 var li = ""; for(var i = 0; i < 5; i++) { li = li + "<li onmousedown=\"setInputValue('" + i + "')\">" + i + "</li>"; }// li = li + "<li onmousedown=\"setInputValue('" + content + "')\">" + content + "</li>"; $('#correlate').append("<ul>" + li + "</ul>"); } /** * 点击关联内容自动设置输入框中的值 */ function setInputValue(content) { $('#content').val(content); $('#correlate').hide(); } //创建XMLHTTP对象 function createXMLHttp() { //大多浏览器适用 if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } if(window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); if(!xmlHttp) { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } } return xmlHttp; } //回调函数 function callback() { //4代表成功 if(xmlHttp.readyState == 4) { //200 if(xmlHttp.status == 200) { var result = xmlHttp.responseText; var json = eval("(" + result + ")"); //展示数据 } } } </script></html>
阅读全文
0 0
- 搜索框提示相关内容
- js搜索提示框
- ajax搜索提示框
- 搜索提示框实现
- google 搜索提示 搜索下拉框 jquery
- android 自定义搜索框 + 搜索提示
- js实现搜索提示框
- “百度搜索框提示”代码
- “百度搜索框提示”代码
- 百度搜索框提示功能
- servlet+ajax搜索框提示
- 搜索框智能提示ajax
- 搜索到的NAS DIY 相关内容
- 相关内容
- 搜索提示
- Ajax搜索框的自动提示功能
- jquery实现搜索框类似提示功
- 基于jquery的搜索框输入提示
- redis源码阅读笔记-- 事件
- Java语法基础练习题1 2017/9/14
- java 反射 joor
- CODE[VS]1023 GPA计算
- Android中JSONObject与JsonObject的区别
- 搜索框提示相关内容
- Mybatis中#和$的区别
- android 浅尝JNI 打包so库
- Android中解决由单例引起的内存泄漏问题
- 遍历目录及子层目录下的所有文件
- 安卓5.1屏蔽recent_apps
- 应用程序无法正常启动(0xc000007b)。请单击确定关闭应用程序
- java基础2
- [err]1292