zoukankan      html  css  js  c++  java
  • 纯Ajax实现Google Suggest功能。

    <scripttype="text/javascript">
          varxmlHttpRequest;
          functioncreateXmlHttpRequest(){
              if(window.ActiveXObject){
                  return newActiveXObject("Microsoft.XMLHTTP");
              }else if(window.XMLHttpRequest){
                  return new XMLHttpRequest();
              }
          }
         
          functionsendData(){
             var context =document.getElementById("context");
             if(context.value.length>0 &&context.value != ""){
                varurl = '${pageContext.request.contextPath}/servlet/AjaxServlet';
                xmlHttpRequest= createXmlHttpRequest();
                xmlHttpRequest.onreadystatechange= ready;
                xmlHttpRequest.open("post",url,true);
                xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlHttpRequest.send("context="+context.value);
             }
          }
         
          functionready(){
             var arr = new Array();
             var tishi =document.getElementById("tishi");
             if(xmlHttpRequest.readyState == 4 &&xmlHttpRequest.status == 200){
                var b = xmlHttpRequest.responseText;
                if(b!= null){
                   repaintDIV(tishi,b);
                 }
             }
          }
         
          functionrepaintDIV(tishi, b){
             tishi.style.display = "block";
             removeAllChild(tishi);
             var arr1 = b.split(" ");
             for(var i = 0; i < arr1.length; i++){
                createNodeDIV(arr1[i]);
             }
          }
         
          functionremoveAllChild(tishi){
             for(var i = 0; i <tishi.childNodes.length; i++){
                tishi.removeChild(tishi.childNodes[i]);
             }
          }
         
          functioncreateNodeDIV(obj){
             var node =document.createElement("div");
             node.style.width = 150;
             node.style.height = 10;
             node.innerHTML = obj;
             node.onmouseover = function(){
                node.style.background="gray";
             }
             node.onmouseout = function(){
                node.style.background="white";
             }
             node.style.display="block";
             document.getElementById("tishi").appendChild(node);
          }
         
          functiondiscover(){
             document.getElementById("tishi").style.display= "none";
          }



  • 相关阅读:
    c#无边框窗体移动 屏蔽双击最大化
    怎么样让代码都带有注释?
    权限设置相关,利用Microsoft.Win32.Security
    计算几何常用算法概览[转]
    VS 常见快捷键
    关于读取txt文件的分段问题
    ajax 常用方法
    文件以附件形式下载的方法
    半角和全角互换
    在ubuntu 中安装 jsdoc
  • 原文地址:https://www.cnblogs.com/pocter/p/3684479.html
Copyright © 2011-2022 走看看