ext 類似百度、google搜尋自動提示,extgoogle

來源:互聯網
上載者:User

ext 類似百度、google搜尋自動提示,extgoogle

在組件上面用keyup事件來監聽

<ext:panel width="210" layout="form" listeners="{afterlayout:onUIShow}" style="margin-left:10px">
                                        <ext:items>
                                            <ext:textField id="query_title333" var="query_title333" fieldLabel="${app:i18n('knowledge.document.search')}"
                                                width="125" listeners="{specialkey:doFileQuery,keyup:inputSuggest}" enableKeyEvents="true" />
                                        </ext:items>
                                    </ext:panel>

js代碼

--斷行符號查詢

 function doFileQuery(o,e){
           if(e.getKey()==13){
                 onFileSearch();
            }
        }

--搜尋提示核心代碼

 function inputSuggest() {

       var txtValue = query_title333.getValue();
       var str = "";
       Ext.Ajax.request({
            params: {txtValue:encodeURI(txtValue)},
            url: "../kbssuggest/findSuggestByValue.action",
            success:function(response) {
                var resp=Ext.util.JSON.decode(response.responseText); 
                if(resp.suggestReslut!="")
                str = resp.suggestReslut.split("#");
                createDiv(str);
            }
        }); 
   }
  
      function onmouseOver1(div) {
         div.style.background="#99BBE8";
         div.style.color="white";
      }
      function onmousetOut1(div) {
        div.style.background="#F2F4F4";
        div.style.color="black";
      }
      function setSuggestValue(value) {
         query_title333.setValue(value);
      }
      function createDiv(str){
          var pop=window.createPopup();
          var len=0;
          if(null!=str&&''!=str){
            len=str.length;
          }
          //設定快顯功能表的內容"+id+"
          //var menuDiv = '<table width="100%" height="100%" cellspacing="0" cellpadding="0" style="border: 1px solid #4482D3; background: #F2F4F4;font-size: 9pt;">';
         var menuDiv='<div class="FONT-SIZE:11pt;font-style: 黑體;font-weight: bold;COLOR:#000000;BACKGROUND-REPEAT:repeat;BACKGROUND-ATTACHMENT:scroll;width:30%;position: absolute;overflow:hidden;z-index: 1000;"><iframe  style="position:absolute;z-index:-1;width:100%;height:100%;background-color:green;top:0;left:0;scrolling:no;" frameborder="0" src="about:blank" mce_src="about:blank"></iframe>';
          for(i=0; i < len - 1; i++) {
             //menuDiv +='<tr><td style="cursor:hand; height: 16px;padding: 2px;padding-left:5px;" align="left" onclick="parent.setSuggestValue(this);" >'
                   menuDiv += '<div onmouseover="parent.onmouseOver1(this);" ';
                   menuDiv += 'onmouseout="parent.onmousetOut1(this);" ';
                   menuDiv += 'onclick="parent.setSuggestValue(this.innerHTML);" ';
                   menuDiv += 'style="background-color: #FFFFFF;padding: 2px 6px 2px 6px;">' + str[i] + '</div>';
                    //menuDiv +=str[i] +'</td></tr>';
                }
              menuDiv+='</div>';  
             // menuDiv += '</table>';
          pop.document.body.innerHTML =menuDiv;
           //選擇右鍵菜單的一項後,菜單隱藏
           pop.document.onclick=function(){
                 pop.hide();
           }
           //得到當前座標
           var e=document.getElementById('query_title333');
           var t=e.offsetTop;
           var l=e.offsetLeft;
           while(e=e.offsetParent)
            { 
                 t+=e.offsetTop; 
                 l+=e.offsetLeft; 
            } 
           //調整快顯視窗的高度
           var high=len*15;
           if(len>4&&len<=7){
             high=len*18;
           }else if(len>7){
             high=len*20;
           }
           pop.show(l+56,t*2.7,130,high,document.body);
      }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.