日期:2014-05-16  浏览次数:20302 次

求教 如何捕获显示/隐藏出发的事件
我有一个table是从属于某个div(中间可能有多层嵌套,所以不能得到这个div)的,我想在table上捕获由于div隐藏/显示触发的事件,请问如何捕获?

我已经尝试过onpropertychange事件,onreadystatechange事件,onactivate事件,ondeactivate事件,请问还有其他办法捕获这种变化吗?



------解决方案--------------------
应该有,up
------解决方案--------------------
js是脚本语言,是可以无限扩展的,这个事件自己写就能实现了~~

手写一个

<html>
<script>
function DecoratorDiv(div){//装饰模式
div.observers=new Array();//观察者模式
div.show=function(){
this.style.display= "block ";
for(var i=0;i <this.observers.length;i++){
var o=this.observers[i];
if(o.actionShow)o.actionShow();
}
}
div.hide=function(){
this.style.display= "none ";
for(var i=0;i <this.observers.length;i++){
var o=this.observers[i];
if(o.actionHide)o.actionHide();
}
}
div.addObserver=function (obj){
this.observers.push(obj);
obj.Div=this;
}
}

window.onload=function(){
var div=document.getElementById( "thediv ");
DecoratorDiv(div);
var table=document.getElementById( "thetable ");
div.addObserver(table);
table.actionShow=function(){
var str= "我根据Div的show事件作出反应,我的ID是 "+this.id+ ",Div的ID是 "+this.Div.id;
alert(str);
}
table.actionHide=function(){
alert( "我的Div隐藏起来了!!! ");
}
}
</script>
<body>

<div id= "thediv ">
<table id= "thetable ">
<tr>
<td> 123123 </td>
</tr>
</table>
</div>
<input type= "button " onclick= "document.getElementById( 'thediv ').show() " value= "Show the Div " />
<input type= "button " onclick= "document.getElementById( 'thediv ').hide() " value= "Hide the Div " />
</body>
</html>