javascript 弹出div实例
来源:互联网 发布:json文件注释怎么写 编辑:程序博客网 时间:2024/06/06 13:08
<html >
<head >
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
<title > </title >
<style type="text/css">
.menuClass
{
background-color:gray;
filter:alpha(opacity=50);
margin-top:-2;
width:98px;
position:absolute;
}
.menuMouseOver
{
background-color:green;
filter:alpha(opacity=50);
width:98px;
}
.menuMouseOut
{
background-color:gray;
filter:alpha(opacity=50);
width:98px;
}
</style>
</head >
<body >
<table>
<tr>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td></td>
</tr>
<tr>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
</tr>
</table>
</body >
</html >
<script language="javascript" type="text/javascript" >
var menu = [ //菜单项数据
{"url":"1.htm",
"text":"menu1"
},
{"url":"2.htm",
"text":"menu2"
},
{"url":"3.htm",
"text":"menu2"
}
];
function getInfo(o){//取得坐标
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
}
function showDrop(o){ //弹出下拉框
var div = document.createElement("div");
div.style.top = o.bottom;
div.style.left = o.left;
var strHTML = "";
div.className = "menuClass";//层样式
document.body.appendChild(div);
//添加菜单项
for(var i=0;i<menu.length;i++)
{
var s = "<span onmouseover=/"this.className='menuMouseOver'/" onmouseout=/"this.className='menuMouseOut'/" onclick=/"menuClick(this,'"+ menu[i].url +"')/">"+menu[i].text+"</span>";
i!=menu.length?strHTML+=s+"<br>":strHTML+=s;
}
div.innerHTML = strHTML;
}
function menuClick(obj,url){ //菜单项单击事件
obj.parentNode.parentNode.removeChild(obj.parentNode);
alert(url);
}
</script >
<head >
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
<title > </title >
<style type="text/css">
.menuClass
{
background-color:gray;
filter:alpha(opacity=50);
margin-top:-2;
width:98px;
position:absolute;
}
.menuMouseOver
{
background-color:green;
filter:alpha(opacity=50);
width:98px;
}
.menuMouseOut
{
background-color:gray;
filter:alpha(opacity=50);
width:98px;
}
</style>
</head >
<body >
<table>
<tr>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td></td>
</tr>
<tr>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
<td> <input type="button" style="width:100px" value="dropButtom" onclick="showDrop(getInfo(this))"/></td>
</tr>
</table>
</body >
</html >
<script language="javascript" type="text/javascript" >
var menu = [ //菜单项数据
{"url":"1.htm",
"text":"menu1"
},
{"url":"2.htm",
"text":"menu2"
},
{"url":"3.htm",
"text":"menu2"
}
];
function getInfo(o){//取得坐标
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
}
function showDrop(o){ //弹出下拉框
var div = document.createElement("div");
div.style.top = o.bottom;
div.style.left = o.left;
var strHTML = "";
div.className = "menuClass";//层样式
document.body.appendChild(div);
//添加菜单项
for(var i=0;i<menu.length;i++)
{
var s = "<span onmouseover=/"this.className='menuMouseOver'/" onmouseout=/"this.className='menuMouseOut'/" onclick=/"menuClick(this,'"+ menu[i].url +"')/">"+menu[i].text+"</span>";
i!=menu.length?strHTML+=s+"<br>":strHTML+=s;
}
div.innerHTML = strHTML;
}
function menuClick(obj,url){ //菜单项单击事件
obj.parentNode.parentNode.removeChild(obj.parentNode);
alert(url);
}
</script >
- javascript 弹出div实例
- JAVASCRIPT弹出DIV
- javascript 弹出div窗体
- JavaScript Div 弹出层 遮罩层
- 弹出一个Panel(DIV),实例代码
- Javascript弹出带关闭的DIV层
- Javascript+div+css(滤镜)弹出窗口
- JavaScript弹出窗口DIV层效果代码
- JavaScript弹出窗口DIV层效果代码 [
- JAVASCRIPT弹出窗口DIV层效果代码
- [Asp.net] JavaScript: DIV 弹出窗口
- javascript+div弹出框(拼接页面)
- 弹出DIV
- 弹出DIV
- 弹出div
- JavaScript 用DIV模拟弹出窗口并跟随窗体滚动
- 利用JavaScript弹出div层,以及递归调用
- JavaScript弹出Div层(嵌入网页) -可拖动
- 无废话C#设计模式之二:Singleton
- 25条CSS编程提醒及小技巧整理
- 75-85年出生的人 教你通过理财赢得未来的30年(一)
- Tomcat简介
- 马桶中的三类人
- javascript 弹出div实例
- 泡妞之享元模式
- 自己开发DB2工具 (7)
- ocsp.properties.sample
- java分页
- 日常操作维护
- Windows Embedded CE 6.0开发初体验(四)跑个应用程序先
- 《诗经·甘棠》:两种相思一样情 转自国学
- SWT Ribbon Control 主页及下载地址, 精彩截屏