搜索框的实现JS

 <script language="javascript" type="text/javascript">         if(typeof String.__Trimed =="undefined"){            String.prototype.trim = function()                 {                      var t = this.replace(/(^/s*)|(/s*$)/g, "");                    return t.replace(/(^ *)|( *$)/g, "");               }            String.__Trimed=true ;      }      function ajaxSeacher(keyTextId,actButtionId,url){                  this.keyContainer=keyTextId ;          this.keyButton=actButtionId ;          this.url=url ;          var cTh=this ;          this.init=function(){              var o=document.getElementById(cTh.keyContainer );              var t=document.getElementById(cTh.keyButton );              if(o.attachEvent){                o.attachEvent("onkeydown",cTh.nameKeyDown);                t.attachEvent("onclick",cTh.bClick );              } else {                 o.addEventListener("keydown",cTh.nameKeyDown);                 t.addEventListener("click",cTh.bClick,false );              }                       }                this.nameKeyDown=function (evt){                if(window.event){                        if(event.keyCode==13 ){                            document.getElementById(cTh.keyButton ).click();                            event.returnValue=false ;                        }                } else {                        if(evt.keyCode==13){                            document.getElementById(cTh.keyButton ).click();                            evt.returnValue=false ;                        }                }                        }                   this.validate=function(){              var o=document.getElementById(cTh.keyContainer );              var v=o.value;              if(v.trim()==""){                 alert("搜索的关键字为空!");                 return false ;              }              return true ;          }          this.bClick=function(evt){                 if(cTh.validate ()==true ){                    window.location.href=url+"?key="+escape(document.getElementById(cTh.keyContainer ).value);                    }                   }                        }      </script>    <div id="ajaxSearch">         <div><a id="ajsNews">新闻</a><a id="ajsCourse">课程</a><a id="ajsKb">知识</a></div>         <input type="text" name="schKey" id="ajaxSechkey" /><input type="button" id="sckBtn"  value ="搜索" />     </div>    <script language="javascript" type="text/javascript">       var aj=new ajaxSeacher("ajaxSechkey","sckBtn","ajaxTree2.htm");       aj.init();    </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值