<div class="codetitle"> <span><a style="CURSOR: pointer" data="36280" class="copybut" id="copybut36280" onclick="doCopy('code36280')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code36280"> <br><br><br><br><title>autoComplete</title> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><style type="text/css"><BR>.autoComplete {margin:8px;position:relative;float:left;}<BR>.autoComplete input {width:200px;height:25px;margin:0;padding:0;line-height:25px;}<BR>.autoComplete ul {z-index:-12;padding:0px;margin:0px;border:1px #333 solid;width:200px;background:white;display:none;position:absolute;left:0;top:28px;*margin-left:9px;*margin-top:2px;margin-top:1px;}<BR>.autoComplete li {list-style:none;}<BR>.autoComplete li a {display:block;color:#000;text-decoration:none;padding:1px 0 1px 5px;_width:97%;}<BR>.autoComplete li a:hover {color:#000;background:#ccc;border:none;}<BR></style> <br><script type="text/javascript"><BR>//<![CDATA[<BR>var getElementsByClassName = function (searchClass, node, tag) {/* 兼容各浏览器的选择class的方法;(:http://www.jb51.net,想了解更多请看这个地址) */<BR> node = node || document, tag = tag ? tag.toUpperCase() : "*";<BR> if(document.getElementsByClassName){/* 支持getElementsByClassName的浏览器 */<BR> var temp = node.getElementsByClassName(searchClass);<BR> if(tag=="*"){<BR> return temp;<BR> } else {<BR> var ret = new Array();<BR> for(var i=0; i<temp.length; i++)<BR> if(temp[i].nodeName==tag)<BR> ret.push(temp[i]);<BR> return ret;<BR> }<BR> }else{/* 不支持getElementsByClassName的浏览器 */<BR> var classes = searchClass.split(" "),<BR> elements = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag),<BR> patterns = [], returnElements = [], current, match;<BR> var i = classes.length;<BR> while(--i >= 0)<BR> patterns.push(new RegExp("(^|s)" + classes[i] + "(s|$)"));<BR> var j = elements.length;<BR> while(--j >= 0){<BR> current = elements[j], match = false;<BR> for(var k=0, kl=patterns.length; k<kl; k++){<BR> match = patterns[k].test(current.className);<BR> if(!match) break;<BR> }<BR> if(match) returnElements.push(current);<BR> }<BR> return returnElements;<BR> }<BR>};<BR>var addEvent=(function(){/* 用此函数添加事件防止事件覆盖 */<BR> if(document.addEventListener){<BR> return function(type, fn){ this.addEventListener(type, fn, false); };<BR> }else if(document.attachEvent){<BR> return function(type,fn){<BR> this.attachEvent(on+type, function () {<BR> return fn.call(this, window.event);/* 兼容IE */<BR> });<BR> };<BR> }<BR>})();<BR>;(function(window){<BR>/* 插件开始 */<BR>var autoComplete=function(o){<BR> var handler=(function(){<BR> var handler=function(e,o){ return new handler.prototype.init(e,o); };/* 为每个选择的dom都创建一个相对应的对象,这样选择多个dom时可以很方便地使用 */<BR> handler.prototype={<BR> e:null, o:null, timer:null, show:0, input:null, popup:null,<BR> init:function(e,o){/* 设置初始对象 */<BR> this.e=e, this.o=o,<BR> this.input=this.e.getElementsByTagName(this.o.input)[0],<BR> this.popup=this.e.getElementsByTagName(this.o.popup)[0],<BR> this.initEvent();/* 初始化各种事件 */<BR> },<BR> match:function(quickExpr,value,source){/* 生成提示 */<BR> var li = null;<BR> for(var i in source){<BR> if( value.length>0 && quickExpr.exec(source[i])!=null ){<BR> li = document.createElement(li);<BR> li.innerHTML = <a href="javascript:;">+source[i]+;<BR> this.popup.appendChild(li);<BR> }<BR> }<BR> if(this.popup.getElementsByTagName(a).length)<BR> this.popup.style.display=block;<BR> else<BR> this.popup.style.display=none;<BR> },<BR> &n <BR></script> </div>