如果进行javascript事件消息传递
一个表格上放了一个div(层)当单击层的某部分内容时我想隐藏层并把当前单击操作传递给底下的表格(或其它内容)请问如何实现呢?
------解决方案--------------------例子:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<html>
<head>
<title> New Document </title>
<script language= "javascript ">
var tabArr=new Array();
//获取所有table的坐标
function initArr()
{
var tabs=document.getElementsByTagName( "TABLE ");
for(i=0;i <tabs.length;i++)
{
var tabRng=new Array();
{
tabRng[0]=tabs[i].offsetLeft;
tabRng[1]=tabs[i].offsetTop;
tabRng[2]=tabs[i].offsetLeft+tabs[i].scrollWidth;
tabRng[3]=tabs[i].offsetTop+tabs[i].scrollHeight;
}
tabArr[i]=tabRng;
}
}
function clickDiv()
{
e=event;
document.getElementById( "Layer1 ").style.display= "none ";
dd(e);
}
function dd(e)
{
if(e!=null)
{
//alert(e.clientX);
var tab=null;
for(i=0;i <tabArr.length;i++)
{
//获得后面的table对象
if(e.clientX> tabArr[i][0] && e.clientX <tabArr[i][2] && e.clientY> tabArr[i][1] && e.clientY <tabArr[i][3])
{
tab=document.getElementsByTagName( "TABLE ")[i];
clickTab(tab);
break;
}
}
}
}
function clickTab(obj)
{
alert(obj.id+ " click method is invoked! ");
}
</script>
</head>
<body onload= "initArr() ">
<table id= "tab1 " width= "200 " border= "1 " cellspacing= "0 " cellpadding= "0 " onclick= "clickTab(this) ">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height= "90 "> </td>
<td> </td>
</tr>
</table>
<table id= "tab2 " width= "200 " border= "1 " cellspacing= "0 " cellpadding= "0 " onclick= "clickTab(this) ">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td height= "90 "> </td>
<td> </td>
</tr>
</table>
<div id= "Layer1 " style= "position:absolute; left:19px; top:20px; width:153px; height:99px; border:1px solid #F00;background-color:#FF0;z-index:1 " onclick= "clickDiv() "> </div>
</body>
</html>