HelloWorld 善战者,求之于势,不责于人;故能择人而任势。

知止而后有定,定而后能静,静而后能安,安而后能虑,虑而后能得。物有本末,事有终始。知所先后,则近道矣。

  BlogJava :: 首页 ::  :: 联系 ::  :: 管理 ::
  167 随笔 :: 1 文章 :: 40 评论 :: 0 Trackbacks

function suggest(src,confield,convalue,operation,thisObj) {
var str = thisObj.value;
var key = window.event.keyCode;
if (key == 40 || key == 38) {
   if (isNull(thisObj.value2)) {
    thisObj.value2 = thisObj.value;
   }
   var suggestDiv = document.getElementById(thisObj.name+"_suggest");
   if (!isNull(suggestDiv)) {
    var divArr = suggestDiv.childNodes;
    var hasIn = false;
    for (var i = 0; i < divArr.length; i++) {
     if(divArr[i].className == "td-across-deep") {
      hasIn = true;
      divArr[i].className = "td-across-low";
      divArr[i].style.backgroundColor = "white";
      if (key == 40) {
       if (i == divArr.length-1) {
        thisObj.value = thisObj.value2;
       } else {
        divArr[i+1].className = "td-across-deep";
        divArr[i+1].style.backgroundColor = "";
        thisObj.value = divArr[i+1].innerText;
       }
      } else if (key == 38) {
       if (i == 0) {
        thisObj.value = thisObj.value2;
       } else {
        divArr[i-1].className = "td-across-deep";
        divArr[i-1].style.backgroundColor = "";
        thisObj.value = divArr[i-1].innerText;
       }
      }
      break;
     }
    }
    if (!hasIn) {
     var i = 0;
     if (key == 38) {
      i = divArr.length-1;
      suggestDiv.scrollTop = 200;
     } else {
      suggestDiv.scrollTop = 0;
     }
     divArr[i].className = "td-across-deep";
     divArr[i].style.backgroundColor = "";
     thisObj.value = divArr[i].innerText;
    } else {
     key == 40 ? (suggestDiv.scrollTop +=17) : (suggestDiv.scrollTop -=17);
    }
    return true;
   }
}
var dbonclick = document.body.onclick
document.body.onclick = function() {
   if(!isNull(dbonclick))
    dbonclick();
   var arr = document.getElementsByTagName("div");
   if (!isNull(arr))
   for (var i = 0; i < arr.length; i++) {
    if (!isNull(arr[i].name))
    if (arr[i].name.indexOf("suggest") >= 0) {
     document.body.removeChild(arr[i]);
    }
   }
   arr = document.getElementsByTagName("iframe");
   if (!isNull(arr))
   for (var i = 0; i < arr.length; i++) {
    if (!isNull(arr[i].name))
    if (arr[i].name.indexOf("suggest") >= 0) {
     document.body.removeChild(arr[i]);
    }
   }
   thisObj.value2 = null;
}
try {
document.body.onclick();
} catch (e) {
   alert(e);
}
if (key == 13 || key ==   27 || isNull(str) || str.trim() == "" ) {
   return true;
}
var h=location.protocol+"//"+location.host+"/";
     var pn=location.href.substring(h.length);
     pn=pn.substring(0,pn.indexOf("/"));
var records=thisObj.name.substring(thisObj.name.lastIndexOf("_")+1);
var fields = confield.split("#");
var conVal = convalue.split("#");
var confields = confield.split("#");
var con = "";
for (var i = 1; i < conVal.length; ++i) {
   var temp = "&fld"+confields[i]+"=";
   if (conVal[i].substring(0,1) == "&") {
    temp += conVal[i].substring(1);
   } else {
    var valObj = document.all["fld_abm"+parseFloat(conVal[i])+"_"+records];
    if (valObj == null) {
     valObj = document.all["fld_abm"+parseFloat(conVal[i])+"_"+1];
    }
    temp += strTrim(getObjValue(valObj));
   }
   con += temp;
}
url="/"+pn+"/FormServlet?act=getSuggest&src="+src+"&field="+confield+con;
     if (operation != null) {
      url += "&operation="+operation;
     }
while (url.indexOf("#") >=0) {
   url = url.replace("#","_");
}
     url+="&suggest="+str;
url = encodeURI(url);
var ajax = new Ajax(url,"post");
var divObj = document.all[thisObj.name+"_suggest"];
var iframeObj = document.createElement("iframe");

iframeObj.id = thisObj.name+"_suggest_iframe";
iframeObj.name = thisObj.name+"_suggest_iframe";
document.body.appendChild(iframeObj);
if (isNull(divObj)) {
   divObj = document.createElement("DIV");
}
divObj.name = thisObj.name+"_suggest";
divObj.id = thisObj.name+"_suggest";
divObj.style.border = '1px';
divObj.isOut = "true";
divObj.onmouseover = "javascript:this.isOut = 'false'";
divObj.onmouseout = "javascript:this.isOut = 'true'";
divObj.style.cursor = "hand";

document.body.appendChild(divObj);
divObj.style.position = "absolute";
ajax.setResponseFun(function(){
   var dom = ajax.getDomDoc();
   if(dom.readyState == 4) {
    var root = dom.documentElement;
    var str = "";
    if (root.childNodes.length == 0) {
     document.body.onclick();
     return true;
    }
    for(var i = 0; i < root.childNodes.length; i++) {
     str+="<div onmouseover='javascript:suggestOver(this);'";
     str+=" onmouseout='javascript:suggestOut(this);' ";
     str+=" onclick='javascript:setSearch(this.innerHTML,\""+thisObj.name+"\");' class='td-across-low' style='background-color:white;'>";
     str+=root.childNodes[i].text+"</div>";
    }
    divObj.innerHTML = str;
    divObj.style.borderBottom = '0.008cm outset ';
    divObj.style.borderRight = '0.008cm outset ';
    divObj.style.borderTop = '0.008cm outset ';
    divObj.style.borderLeft = '0.008cm outset ';
    divObj.style.overflowY = "auto";
    divObj.style.height = divObj.offsetHeight > 300 ? 300 : divObj.offsetHeight;
    var oRect = thisObj.getBoundingClientRect();
    divObj.style.left = oRect.left;
    divObj.style.top = oRect.top + 18;
    divObj.style.width = thisObj.clientWidth+2;
    try {
     var iobj = document.getElementById(thisObj.name+"_suggest_iframe");
     iobj.style.position = "absolute";
     iobj.style.left = divObj.offsetLeft;
     iobj.style.top = divObj.offsetTop;
     iobj.style.height = divObj.offsetHeight;
     iobj.style.width = divObj.offsetWidth;
    } catch(e){}
   }
});
ajax.send();
return true;
}

function suggestOver(obj) {
for(var i = 0; i < obj.parentNode.childNodes.length; i++) {
   obj.parentNode.childNodes[i].className = "td-across-low";  
   obj.parentNode.childNodes[i].style.backgroundColor = "white";
}
obj.className = "td-across-deep";
obj.style.backgroundColor = "";
}

function suggestOut(obj) {
obj.className = "td-across-low";
obj.style.backgroundColor = "white";
}

function setSearch(value,thisObjName) {
document.all[thisObjName].value = value;
try {
document.body.removeChild(document.getElementById(thisObjName+"_suggest_iframe"));
document.body.removeChild(document.getElementById(thisObjName+"_suggest"));
} catch (e){}
}

function hideSuggest(thisObj) {
var obj = document.getElementById(thisObj.name+"_suggest");
if ( isNull(obj) ) {
   return true;
} else {
   if (obj.isOut == "true") {
    document.body.removeChild(document.getElementById(obj.name+"_suggest_iframe"));
    document.body.removeChild(obj);
   }
}
return true;
}



</script>

posted on 2007-08-13 18:56 helloworld2008 阅读(501) 评论(0)  编辑  收藏 所属分类: html/javascript/css

只有注册用户登录后才能发表评论。


网站导航: