加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

纯Ajax实现Google Suggest功能。

发布时间:2020-12-15 21:00:28 所属栏目:百科 来源:网络整理
导读:scripttype="text/javascript" varxmlHttpRequest; functioncreateXmlHttpRequest(){ if(window.ActiveXObject){ return newActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ return new XMLHttpRequest(); } } functionsendData(){ v
<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";
      }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读