乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      仿百度搜索智能提示(純JS實(shí)現(xiàn))

       ZackEdge 2015-02-17

      項(xiàng)目中經(jīng)常用到搜索智能提示,開源的象jQuery、yui等都有,但是覺得有點(diǎn)臃腫,于是自己用ajaxpro+JavaScript搞了一個(gè)

      目前只支持ie,可能還有若干個(gè)bug。相信新手應(yīng)該用得著吧,老鳥就算了。

      大家發(fā)現(xiàn)了請(qǐng)指出,我馬上改正,大家多多支持哈~~

      核心代碼如下:

       

      代碼
      var arrList = new Array();//要搜索的數(shù)據(jù)
      var objouter, objInput, objInputId = "txtSearch";//控件ID
      var selectedIndex = -1, intTmp;
      //初始化
      function smanPromptList() {
      this.style = "overflow:hidden;width:393px;height:auto;background:#FFFFFF;border:1px solid #000000;font-size:14px;cursor:default;"
      if (arrList.constructor != Array) {
      alert('smanPromptList初始化失敗:第一個(gè)參數(shù)非數(shù)組!');
      return;
      }
      document.write("<div id='__smanDisp' style='position:absolute;display:none;" + this.style + "' onblur></div>");
      document.write("<style type=\"text/css\">.sman_selectedStyle{background-Color:#3366CC;color:#FFFFFF}</style>");

      arrList.sort(function(a, b) {
      if (a.length > b.length) return 1;
      else if (a.length == b.length) return a.localeCompare(b);
      else return -1;
      });
      objouter = document.getElementById("__smanDisp") //顯示的DIV對(duì)象
      objInput = document.getElementById(objInputId); //文本框?qū)ο?BR>if (objInput == null) {
      alert('smanPromptList初始化失敗:沒有找到"' + objInputId + '"文本框');
      return;
      }
      objInput.onblur = function() { objouter.style.display = 'none'; }
      objInput.onkeyup = checkKeyCode;
      objInput.onfocus = checkAndShow;
      }

      function getAbsoluteHeight(ob) {
      return ob.offsetHeight;
      }
      function getAbsoluteWidth(ob) {
      return ob.offsetWidth;
      }
      function getAbsoluteLeft(ob) {
      var s_el = 0, el = ob;
      while (el) {
      s_el = s_el + el.offsetLeft;
      el = el.offsetParent;
      };
      return s_el;
      }
      function getAbsoluteTop(ob) {
      var s_el = 0, el = ob;
      while (el) {
      s_el = s_el + el.offsetTop;
      el = el.offsetParent;
      };
      return s_el;
      }
      function outSelection(Index) {
      objInput.value = objouter.children[Index].innerText.Trim();
      objouter.style.display = 'none';
      }
      function divPosition() {
      objouter.style.top = getAbsoluteHeight(objInput) + getAbsoluteTop(objInput);
      objouter.style.left = getAbsoluteLeft(objInput);
      objouter.style.width = getAbsoluteWidth(objInput);
      }
      function chageSelection(isUp) {
      if (objouter.style.display == 'none') {
      objouter.style.display = '';
      }
      else {
      if (isUp)
      selectedIndex++;
      else
      selectedIndex--;
      }
      var maxIndex = objouter.children.length - 1;
      if (selectedIndex < 0) { selectedIndex = 0; }
      if (selectedIndex > maxIndex) { selectedIndex = maxIndex; }
      if (selectedIndex == maxIndex) { selectedIndex = -1; }

      for (intTmp = 0; intTmp <= maxIndex; intTmp++) {
      if (intTmp == selectedIndex) {
      objouter.children[intTmp].className = "sman_selectedStyle";
      objInput.value = objouter.children[selectedIndex].innerText.Trim();
      }
      else {
      objouter.children[intTmp].className = "";
      }
      }
      }
      function checkKeyCode() {
      var ie = (document.all) ? true : false
      if (ie) {
      var keyCode = event.keyCode
      if (keyCode == 40 || keyCode == 38) {
      var isUp = false
      if (keyCode == 40)
      isUp = true;
      chageSelection(isUp)
      }
      else if (keyCode == 13) {
      outSelection(selectedIndex);
      }
      else {
      checkAndShow();
      }
      }
      else {
      checkAndShow();
      }
      divPosition();
      }

      function checkAndShow() {
      var strInput = objInput.value.Trim();
      if (strInput != "") {
      divPosition();
      selectedIndex = -1;
      arrList.length = 0;
      objouter.innerHTML = "";
      //=======================這里修改數(shù)據(jù)================================
      var result = WebApplicationTestDiv.WebForm11.GetArray(strInput).value;
      //===================================================================
      var data = eval('(' + result + ')');
      for (var j = 0; j < data.length; j++) {

      arrList[j] = data[j];
      }

      for (intTmp = 0; intTmp < arrList.length; intTmp++) {
      for (i = 0; i < arrList[intTmp].length; i++) {
      if (arrList[intTmp].substr(i, strInput.length).toUpperCase() == strInput.toUpperCase()) {
      addOption(arrList[intTmp], strInput);
      }
      if (objouter.childNodes.length >= 10) {
      break;
      }
      }
      }
      if (objouter.childNodes.length > 0) {
      objouter.innerHTML += "<div style=\"width:395px;height:22px;text-align:right;color:Blue;text-decoration:underline;cursor:pointer;\">關(guān)閉</div>";
      }
      objouter.style.display = '';
      }
      else {
      objouter.style.display = 'none';
      }
      }
      //顯示搜索的數(shù)據(jù)并關(guān)鍵字涂色
      function addOption(value, keyw) {
      var v = value.replace(keyw, "<b><font color=\"red\">" + keyw + "</font></b>");
      objouter.innerHTML += "<div style=\"width:395px;height:22px\" onmouseover=\"this.className='sman_selectedStyle'\" onmouseout=\"this.className=''\" onmousedown=\"document.getElementById('" + objInputId + "').value='" + value + "'\">" + v + "</div>"
      }
      String.prototype.Trim = function() {
      return this.replace(/(^\s*)|(\s*$)/g, "");
      }
      smanPromptList();
       

       

      后臺(tái)核心代碼:

       


      代碼
      [AjaxPro.AjaxMethod]
      public string GetArray(string name)
      {
      try
      {
      List<string> list = new List<string>();
      #region
      list.Add("1");
      list.Add("12");
      list.Add("123");
      list.Add("1234");
      list.Add("12345");
      list.Add("123456");
      list.Add("1234567");
      list.Add("12345678");
      list.Add("123456789");
      list.Add("9876543210");
      list.Add("987654321");
      list.Add("98765432");
      list.Add("9876543");
      list.Add("987654");
      list.Add("98765");
      list.Add("9876");
      list.Add("987");
      list.Add("98");
      list.Add("9");
      list.Add("1111222");
      list.Add("1sdfsdf.comdos32.cn");
      list.Add("111222.comdos32.cn");
      list.Add("a11sdafs.netdos32.cn");
      list.Add("b22dsafsdfdos32.cn");
      list.Add("c333asdfsadfdos32.cn");
      list.Add("4444dsafasdfdos32.cn");
      list.Add("dddsfddsafdsafdos32.cn");
      list.Add("121213dsafsdafdos32.cn");
      list.Add("43213asdfadsfdos32.cn");
      list.Add("dsa3121dasf3dos32.cn");
      list.Add("a213dos32.cn");
      list.Add("323313dos32.cn");
      list.Add("3213dos32.cn");
      list.Add("32213dos32.cn");
      list.Add("dsfsdddddos32.cn");
      list.Add("ds911dfsfddos32.cn");
      list.Add("ffdafddos32.cn");
      list.Add("楊瀾");
      list.Add("楊揚(yáng)");
      list.Add("楊白勞");
      list.Add("楊鈺瑩");
      list.Add("楊百萬");
      list.Add("楊一洋");
      list.Add("楊丞琳");
      list.Add("楊一爾");
      list.Add("楊二爾");
      #endregion
      List<string> l1 = list.FindAll(delegate(string ss) { return ss.Contains(name); });
      string str = "[";
      foreach (string s in l1)
      {
      str += "\"" + s + "\"" + ",";
      }
      str = str.TrimEnd(',') + "]";
      return str;
      }
      catch (Exception ex)
      {
      throw ex;
      }
      }
       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多