var iResultLength = 0;//结果的条数 var iCurIndex = -1;//当前所在游标,默认为-1代表当前选中的结果是输入框 var sInputValue = "";//用户自己输入的内容 var oCurDatas = null;//当前数据josn返回的 var sLastSuggestValue = "";//上次选中的提示结果(包括用户自己输入的内容):目的用于验证本次文本框是否和上次值一样,如果一样则忽略,避免重复提交 //保存关键字 function saveKey(key){ /* if(key=="") return; $.get("hit.jsp",{key:key,rand:Math.random()},function(data){}); */ } //select onpress事件 function selectPress(url,dono,colname,obj,keyCode){ var sValueTmp = String.fromCharCode(keyCode); if(obj.getAttribute("ValueTime")==undefined || obj.getAttribute("ValueTime")==null) obj.setAttribute("ValueTime",(new Date()).getTime()); else{ var lasttime = parseInt(obj.getAttribute("ValueTime")); var thistime = (new Date()).getTime(); //alert(thistime+"|" + lasttime + "|" + (thistime-lasttime)); if(thistime-lasttime>2000){//超过2秒则清空数据 obj.setAttribute("TmpValue",""); } obj.setAttribute("ValueTime",thistime); } if(obj.getAttribute("TmpValue")==undefined || obj.getAttribute("TmpValue")==null) obj.setAttribute("TmpValue",sValueTmp); else{ sValueTmp = obj.getAttribute("TmpValue") + sValueTmp; obj.setAttribute("TmpValue",sValueTmp); } $.ajax({ url:url, type:"GET", data:{key:sValueTmp,dono:dono,colname:colname,rand:Math.random()}, dataType:"html", success:function(data){ var value = showresultForSelect(data); //根据值显示选项 for(var i=0;i0) value = oCurDatas[0].tradeValue; return value; } //结果处理 function showresult(transport,inputobj){ //获得搜索提示结果的元素 var resultDiv = createSearchNode(inputobj); //document.getElementById("search_suggest"); var list = eval("(" + transport + ")"); oCurDatas = list.data; iResultLength = oCurDatas.length;//获得搜索总数 if(iResultLength<=0){ resultDiv.innerHTML = ''; resultDiv.style.display = 'none'; return; } resultDiv.style.display = 'block'; //清除上一次的搜索结果 resultDiv.innerHTML = ''; for(var i=0;i' + ''+oCurDatas[i].tradeKey+' '; if(oCurDatas[i].tradeTitle=='' || oCurDatas[i].tradeTitle==null || oCurDatas[i].tradeTitle==undefined) suggest+= ''+oCurDatas[i].tradeValue+' '; else suggest+= ''+oCurDatas[i].tradeTitle+'['+ oCurDatas[i].tradeValue +'] '; //+ ''+oCurDatas[i].tradeTitle+'' suggest += ''; resultDiv.innerHTML += suggest; } resultDiv.innerHTML += ''; } //移动结果项 function movePosition(inputobj,step){ iCurIndex += step; if(iCurIndex==-2){//已经到头,则返回搜索结果列表的最后一个元素 iCurIndex = iResultLength-1; } else if(iCurIndex==iResultLength){//已经到尾,则返回自己输入的最原始的数据 iCurIndex = -1; } //赋值操作 if(iCurIndex==-1) inputobj.value = sInputValue; else inputobj.value = $.trim(oCurDatas[iCurIndex].tradeValue); sLastSuggestValue = inputobj.value; //清除所有的搜索结果列表样式 for(var i=0;i-1) document.getElementById('div_result' + iCurIndex).className = 'suggest_link_over'; } //处理结果项上移up 下移down的事件 function inputUpDown(url,inputobj,dono,colname,keyCode){ //alert(document.getElementById("search_suggest")); if(inputobj.value=='' && document.getElementById("search_suggest")==null) searchSuggest(url,inputobj,dono,colname,keyCode); else{ if(keyCode==38)movePosition(inputobj,-1);//up if(keyCode == 40)movePosition(inputobj,1);//down } } //输入框的回车事件的处理 function inputEnter(inputobj,keyCode){ if(keyCode==13){ clearResource(inputobj); //隐藏搜索结果提示框 //document.getElementById("search_suggest").style.display = 'none'; //保存关键字 //saveKey(value); } } //改变鼠标移动到选项时的css样式 function suggestOver(obj,index){ //清除所有的搜索结果列表样式 window.status = iResultLength; for(var i=0;i