<textarea class="xhtml:nogutter" name="code" rows="15" cols="50"><html><head><meta http-equiv="Content-Type" content="text/html;charset=gb2312"><mce:style><!--#wd { border:solid 1px #999; font-size:14px; padding:4px; }#wd_box { border:solid 1px #999; background-color:#fff; position:absolute; z-index:1001px;}#wd_box a { display:block; padding:4px; color:#000; cursor:default; text-decoration:none; font-size:13px; }#wd_box a:hover { background-color:#0066cc; color:#fff; }--></mce:style><style mce_bogus="1">#wd { border:solid 1px #999; font-size:14px; padding:4px; }#wd_box { border:solid 1px #999; background-color:#fff; position:absolute; z-index:1001px;}#wd_box a { display:block; padding:4px; color:#000; cursor:default; text-decoration:none; font-size:13px; }#wd_box a:hover { background-color:#0066cc; color:#fff; }</style></head><body><input id="wd" type="text" size="50" value="" /><input type="button" value="百度搜索" οnclick="search()" /><mce:script type="text/javascript"><!--var K = document.getElementById("wd");//获取匹配项function getword(){hideD();var V = K.value;if(!V) return;var doma = [];doma.push("sugge.stion");doma.push("baidu");doma.push("com");var U = 3;var C = document.createElement("SCRIPT");C.src="http://"+doma.join('.').replace('.','')+"/su?wd="+encodeURIComponent(V)+"&p="+U+"&t="+(new Date()).getTime();C.charset="gb2312";document.body.appendChild(C);}if(window.baidu==null) window.baidu={};baidu.sug = function(data){ len = data.s.length; if(len==0)return; var s = []; var vd = "javascript:void(0);"; var focus = "javascript:setV(this);"; var blur = "javascript:leaveA(this);"; for(var i=0;i<data.s.length;i++){ s.push("<a lang='"+i+"' href=""+vd+"" mce_href="&quot;+vd+&quot;" οnfοcus='"+focus+"' οnblur='"+blur+"' οnclick='"+focus+"hideD();'>"+data.s[i]+"</a>"); } show(s);};//显示匹配项function show(s){var div = document.createElement("div");div.style.left = K.offsetLeft+"px";div.style.top = K.offsetTop+20+"px";div.style.width = K.offsetWidth+"px";div.id = "wd_box";div.innerHTML = s.join('');document.body.appendChild(div);div.onmouseover = function(){overD=true;};div.onmouseout = function(){overD=false;};overD = true;}//为搜索框赋值function setV(e){ K.value = e.innerHTML; indx = parseInt(e.lang); e.style["backgroundColor"] = "#0066cc"; e.style["color"] = "#ffffff";}function leaveA(e){ e.style["backgroundColor"] = "#ffffff"; e.style["color"] = "#000000";}//隐藏匹配层var overD = false;function hideD(){ var div = document.getElementById("wd_box"); if(div) document.body.removeChild(div); indx = -1; len = 0;}//搜索function search(){ window.location = "http://www.baidu.com/s?wd="+K.value;}//关键字改变时自动匹配var kv = "";setInterval(function(){ if(indx==-1 && K.value!=kv){ kv = K.value; getword(); }},100);//初始化控件事件window.onload = function(){document.body.onclick = function(){ if(!overD) hideD();};K.onkeydown = function(){indx=-1;};K.onmouseover = function(){overD=true;};K.onmouseout = function(){overD=false;};}//设置匹配项焦点function setFocus(){ var arr = document.getElementById("wd_box").getElementsByTagName("A"); arr[indx].focus();}var indx = -1;//焦点所在索引var len = 0;//匹配项个数//按下上下键document.οnkeydοwn=function(ev){ev = ev || event;var code = (ev.keyCode||ev.which);if(code==9||code==13){ search(); return;}if(code==38){//up if(indx<=0)return; indx--; setFocus();}else if(code==40){//down if(indx+1==len)return; indx++; setFocus();}};// --></mce:script></body></html></textarea>
作者:朱会震