日期:2014-05-16  浏览次数:20768 次

Ajax实现输入框自动下拉提示

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
??? <base href="<%=basePath%>">
???
??? <title>My JSP 'index.jsp' starting page</title>
?<meta http-equiv="pragma" content="no-cache">
?<meta http-equiv="cache-control" content="no-cache">
?<meta http-equiv="expires" content="0">???
?<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
?<meta http-equiv="description" content="This is my page">
?<!--
?<link rel="stylesheet" type="text/css" href="styles.css">
?-->
?<script type="text/javascript" src="jquery-1.5.2.js"></script>
?<script type="text/javascript">
?$(document).ready(function(){
??$(document).bind('click', Hide);
?});
?
?
?function Hide(e){
???? if($(e.target)[0].id =="like")
???????? return;
???? $("#like").hide();
?}
?
?
?var temp = "";
?function fouc(){
??var intervalid;
??intervalid = setInterval("getconclusionName()", 200);
?}
?
?
?function getconclusionName(){
?var conclusionName="";
?conclusionName = $("#csn").val();
??if (conclusionName != ""){
???if(temp !=conclusionName){
????? temp= conclusionName;
????? sendConclusion(temp);
???}
??}
?}
?
?
?function unfouc() {
?$("#like").html("");
?$("#like").css("display","none");
?}
?
?
?function sendConclusion(conclusionName) {
??$.ajax( {
???type : "post",
???url : "http://localhost:8080/JqueryInput/servlet/NameServlet",
???data: "conclusionName=" + conclusionName,
???timeout : 20000,
???success :? function(data) {
????var str ="";
????var str1="";
????$.each(data, function(i, n) {
?????if ("medicalConclusionVOList"==i){
??????if(n.length == 0){
???????$("#like").css("display","none");
??????}else{
???????for(var j=0;j<n.length;j++){
???????? str1=n[j];
???????? str+="<span id=\""+j+"\" onclick=select(\'"+str1.conclusionId+"\',\'"+str1.name+"\')>"+n[j].name+"</span>"+"<br><div class=\"line_style1-1\"></div>";
???????}
???????$("#like").css("display","block");
??????}
?????}
????});
????$("#like").html(str);
???}?
??});
?}
?
?//查询汇总项目
?function searchBigProject(){
??var key=window.event.keyCode;
??var len = 0;???????//搜索结果的行数
??if(document.getElementById("searchTable") != null){
???len = document.getElementById("searchTable").rows.length;
??}
?? //如果不是按的上下键或回车键,就向服务器发送异步数据请求
??????? if(key!=38 && key!=40 && key!=13){
???var vProjectName = "%"+document.getElementById("bigProjectName").value+"%";
???if(vProjectName == "%%"){
????return;
???}
???$.ajax( {
????type : "post",
????url : "http://localhost:8080/JqueryInput/servlet/ProjectServlet",
????timeout : 20000,
????
????success :? function(data) {
?????callback(data);
????}?
???});
??}else{??//如果按的是上下键或回车
???if(len == 0) {
?????????????? return ;
??????????? }
???//检查当前有无鼠标选中
??????????? var isCheck=checkSelect();
???if(isCheck == -1)
??????????? {
?????????????? document.getElementById("searchTable").rows(0).style.background = "#FF9933";
??????????? }else{
???????????? if(key == 38){?//按下上方向键
???????????????? if(isCheck==0)
???????????????? {
??????????????????? return;
???????????????? }
???????????????? else
???????????????? {
????????????????????? //清空所有搜索框<TR>标签的背景
???????????????????? cleanTr();
??????document.getElementById("searchTable").rows(parseInt(isCheck)-parseInt(1)).style.b