注意:
<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)+"' onmouseover='forceMenuItem( "+(i+1)+");'width='100%' onclick='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>
分享到:
- 2009-01-09 11:26
- 浏览 2032
- 评论(6)
- 论坛回复 / 浏览 (6 / 5037)
- 查看更多
相关推荐
动态生成div框并且同时加载数据,当数据量大的时候大大节省数据回访时间
让iframe 显示在 指定的div下面 针对ie6 select挡住div 的bug 采用 iframe来当作div的底 * * @param string divId 需要解决的div层 * @param string iframeId 采用的 IFRAME ,如果不指定 自动生成一个...
解决IE6 中select 穿透 div 等层的问题
用DIV模仿SELECT下拉框 function replaceSelects() { try{ for (i=0;i;i++){ // 隐藏 select selects[i].style.display = 'none'; select_divTag = document.createElement('div'); select_divTag.id = ...
select 在ie6下覆盖div bug 解决方案。 div 模拟select 单选 在 body onload事件中调用init_select方法就可,参数传相关背景图片就可。我都已经放到资源包下了。
介绍: 效果演示:麦田圈 只要在层里面加上下面代码就可以了~ <iframe src="" frameborder=0></iframe>
select ——使用DIV 实现 Select js源码
NULL 博文链接:https://lk617238688.iteye.com/blog/763608
div 模拟 select 多选 实现还有点bug,望大家一起改正。
使用div模拟select效果,可点击页面其他任意地方隐藏下拉框
Div下拉菜单被Select挡住的解决办法 下拉菜单 bbbbbbb ccccccc ccccccc ccccccc ccccccc test0 test1 test2 test3 Div被Select挡住,是一个比较常见的问题。 有的朋友通过把div的内容放入iframe或object里来...
jquery DIV模拟select,样式美观、大方、可自己更换背景、不懂的私我
参考这篇文章实现了动态生成div对象,在利用id获取这些对象时结果一直是undefined,分析发现是因为div由ng-repeat动态生成,在页面渲染完成前id是未知的,因此不能用id去获取div,只要把相关代码写在页面渲染完成的...
Div下拉菜单被Select挡住的解决办法</title> </head><body> <div style=”z-index: 10; position: absolute; width: 100; height: 18; overflow: hidden;” onmouseover=”this....
jQuery+div+css模拟select自定义下拉列表框,简单轻巧实用。
div+css打造select下拉菜单,可自己修改相应样式!!!
非常好用的Select插件,通过制作的jQ插件快速生成Selcet 前台界面只需要一个div元素,其他的可以通过插件的API进行数据的填充与获取,demo中都有具体事例
NULL 博文链接:https://duinibuhaome.iteye.com/blog/855013
div+css模拟select
jQuery div仿select下拉选项菜单美化获取html jQuery div仿select下拉选项菜单美化获取html jQuery div仿select下拉选项菜单美化获取html jQuery div仿select下拉选项菜单美化获取html