解决 动态生成div,被select挡住的问题。。

注意:
<iframe id='ifmout' style='position:absolute;z-index:0;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);' frameborder='0' ></iframe>
很多资料都写-1,,

这是浏览器IE7版本之前会出现的问题,IE7,是不会有这个问题的啦。。
哈哈哈。。这是,整理后的代码。。防止自己忘了。做个备份啦。。
再次,感谢老公的帮助哟。
在生成div时,先生成的Ifame,在移除DIV时,也要移除ifame......



<script>
var inputname;
var now;//
var menuFocusIndex; //当前选中行
var arrylist;//当前返回数组
var resultlength=0;//当前数组长度
function getPosition(obj)//获取当前操作坐标
{
var top = 0,left = 0;
do
{
top += obj.offsetTop;
left += obj.offsetLeft;
}
while ( obj = obj.offsetParent );
var arr = new Array();
arr[0] = top;
arr[1] = left;
return arr;
}
function createMenu(result)//生成div
{
var textBox=inputname;
var menuid="divout";
var divouter;
if( document.getElementById(menuid) == null )
{
ifm=document.createElement("<iframe id='ifmout' style='position:absolute;z-index:0;width:expression(this.nextSibling.offsetWidth);height:expression(this.nextSibling.offsetHeight);top:expression(this.nextSibling.offsetTop);left:expression(this.nextSibling.offsetLeft);' frameborder='0' ></iframe>");
var left_new=getPosition(textBox)[1];
var top_new=getPosition(textBox)[0];
var newControl = document.createElement("div");
newControl.id = menuid;
document.body.appendChild(ifm);
document.body.appendChild(newControl);
newControl.style.position = "absolute";
newControl.style.border = "solid 1px #0000CC";
newControl.style.backgroundColor = "#FFFFFF";
newControl.style.width = 350 + "px";
newControl.style.left = left_new + "px";
newControl.style.top = top_new+ 2 +20+ "px";
try{
newControl.style.font=14+"px";}
catch(err){}
divouter= newControl;
}
else
divouter= document.getElementById( menuid );
divouter.innerHTML =result;
}
function createMenuBody(resultlist)//根据返回数组生成div中行
{
var result="";
var j = 0;
arr = resultlist;
arrylist =arr;
if(arr.length > 10)
{
j = 10;
}
else
{
j = arr.length;
}
resultlength=j;
if(j >0)
{
for ( var i = 0; i < j; i++ ){
arrtab = arr[i].childNodes;
text1 ="";
text2 ="";
text3 ="";
if(arrtab.length>=1)text1 = arrtab[0].childNodes[0]==null?"":arrtab[0].childNodes[0].nodeValue;
if(arrtab.length>=2)text2 = arrtab[1].childNodes[0]==null?"":arrtab[1].childNodes[0].nodeValue;
if(arrtab.length>=3)text3 = arrtab[2].childNodes[0]==null?"":arrtab[2].childNodes[0].nodeValue;
result += "<table border='0' cellpadding='2' cellspacing='0' id='menuItem"+(i+1)+"' οnmοuseοver='forceMenuItem( "+(i+1)+");'width='100%' οnclick='givNumber("+i+");'><tr><td align='left' width='100px'>" + text1+ "</td><td align='left' width='180px'>" + text2+ "</td><td align='left' width='70px'>" + text3+ "</td></tr></table>";
createMenu(result);
}
}
else
{
var div = document.getElementById("divout");
if(div)div.parentNode.removeChild(div);
var ifm = document.getElementById("ifmout");
if(ifm)document.body.removeChild(ifm);
}
}
function forceMenuItem(index)//div中颜色变化
{
lastMenuItem = document.getElementById("menuItem" + menuFocusIndex);
if (lastMenuItem != null)
{
lastMenuItem.style.backgroundColor="white";
lastMenuItem.style.color="#000000";
}
var menuItem = document.getElementById("menuItem" + index);
if (menuItem == null)
{
document.getElementById("txt1").focus();
}
else
{
menuItem.style.backgroundColor = "#5555CC";
menuItem.style.color = "#FFFFFF";
menuFocusIndex = index;
}
}
function givNumber(index)//赋值移除div
{
inputname.value = arrylist[index].childNodes[0].childNodes[0].nodeValue ;
inputname.focus();
var div = document.getElementById("divout");
if(div)div.parentNode.removeChild(div);
var ifm = document.getElementById("ifmout");
if(ifm)document.body.removeChild(ifm);
menuFocusIndex=null;
}
function catchKeyBoard()//按键事件
{
var keyNumber = event.keyCode;
if(document.getElementById("divout")==null){
return;
}
if(keyNumber=='40') //向下
{
if (menuFocusIndex==null) //当焦点在文本框中间时,按向下跳到第一个主体。
{
forceMenuItem(1);
}
else if(menuFocusIndex==resultlength)//当焦点超出界限时跳转到第一个主体
{
forceMenuItem(1);
}
else
{
forceMenuItem(menuFocusIndex+1); //焦点增加1
}
}
else if(keyNumber=='38')//向上
{

if(menuFocusIndex==1)
{
forceMenuItem(resultlength);
}else if(menuFocusIndex == null){
forceMenuItem(1); //焦点1
}else
{
forceMenuItem(menuFocusIndex-1); //焦点减少1
}
}
else if(keyNumber=='13')
{
givNumber(menuFocusIndex-1);
}
}
function DisplayUserInformation(obj,tonow)//ajax方法调用
{
now = tonow;
inputname=obj;
var keyNumber = event.keyCode;
if(keyNumber=='40'||keyNumber=='38'||keyNumber=='13')
catchKeyBoard();
else//调用ajax
{
var url = "";
var canshu=inputname.value;
if(canshu!="")
{
ajaxStart(canshu);
}
else
{
var div = document.getElementById("divout");
if(div)div.parentNode.removeChild(div);
var ifm = document.getElementById("ifmout");
if(ifm)document.body.removeChild(ifm);

}
}
}
function InputOnBlur()//失去焦点
{
setTimeout("InputOnBlurTimeOut()",300);
}
function InputOnBlurTimeOut()//失去焦点
{
menuFocusIndex=null;
var div = document.getElementById("divout");
if(div)div.parentNode.removeChild(div);
var ifm = document.getElementById("ifmout");
if(ifm)document.body.removeChild(ifm);
}
//ajax
var XmlHttpObject;
function StateEvent()
{

if(XmlHttpObject.readyState == 4)
{
if(XmlHttpObject.status == 200)
{
xmlDoc=XmlHttpObject.responseXML.documentElement;
result=xmlDoc.getElementsByTagName("Sssq");

if(result.length==0){
inputobj = inputname;
inputobj.value=inputobj.value.substring(0,inputobj.value.length-1);
}else{
createMenuBody(result);
}

result=xmlDoc.getElementsByTagName("ZhiYe");
if(result.length==0){
inputobj = inputname;
inputobj.value=inputobj.value.substring(0,inputobj.value.length-1);
}else{
createMenuBody(result);
}
}
}
}
function CreateXmlHttp()
{
if(window.ActiveXObject)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
return new XmlHttpRequest();
}
}
function ajaxStart(q)
{
var ParamString = "q="+q+"&now="+now;
XmlHttpObject = CreateXmlHttp();
XmlHttpObject.onreadystatechange = StateEvent;
XmlHttpObject.open("post","ajaxjsp.jsp",true);
XmlHttpObject.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); //设置服务器响应请求体参数
XmlHttpObject.send(ParamString);
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值