在jsp中的文本框输入部分信息后出现像google中那样的记忆功能
请高手提示一下

解决方案 »

  1.   

    觉得应该是把历史数据记录在Cookie上, 在文本框获得焦点的时候用一个div把Cookie里面的数据显示出来吧
      

  2.   

    是输入事件触发ajax去查找数据,然后下拉显示吧
      

  3.   

    http://www.sosuo8.com/article/show.asp?id=1551
      

  4.   

    同意二楼
    <script language="javascript">
    var xmlhttp;
    function createxmlhttp()
    {
    if(window.XMLHttpRequest)
    {
    xmlhttp=new XMLHttpRequest();
    }else if(window.ActiveXObject)
    {
    try{
    xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
    xmlhttp=new ActiveXObject("Microsoft.XMLHttp");
    }
    }
    }
    function givev(o)
    {
    document.getElementById("nm").value=o.innerHTML;
    document.getElementById("kk").innerHTML="";
    }
    function flush()
    {
    if(document.getElementById("nm").value=="")
    {
    setTimeout(flush(),20);}
    }
    function change()
    {
    if(xmlhttp.readyState==4)
    {
    var array=xmlhttp.responseText.split("$");
    document.getElementById("kk").innerHTML="";
    for(var i=0;i<array.length;i++)
    {
    document.getElementById("kk").innerHTML+="<label onmouseover=this.style.background='cccccc',this.style.cursor='pointer' onmouseout=this.style.background='while' onclick='givev(this)'>"+array[i]+"</label><br>"
    }
    }
    }
    function con()
    {
    alert(0);
    var value=document.getElementById("nm").value;
    alert(1);
    createxmlhttp();
    alert(2);
    xmlhttp.open("post","checkbox.do",true);
    alert(3);
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8'); 
    alert(4);
    xmlhttp.onreadystatechange=change;
    alert(5);
    xmlhttp.send("checknamevalue="+value);
    alert(6);
    }
    </script>
    <style type="text/css">
    <!--
    #kk {
    position:absolute;
    width:168px;
    height:130px;
    z-index:1;
    left: 10px;
    top: 34px;
    }
    -->
    </style>
    </head>
    <body onload="flush()">
    <input type="text" name="checkname" id="nm" onkeyup="con()">
    <div id="kk"></div>
    </body>
    </html>
    后台代码就不用写了吧,取出checknamevalue的值,用模糊查询查处所有的相似值,用$连接成一个字符串传到前台,然后处理就好了