事实上我感觉由于父结点状态变化导致子节点表现变化,似乎是不能通过捕获的,因为子节点的状态是没有变化的,有变化的是offsetWidth之类的属性,但是这些属性又不能出发propertychange事件。
解决方案 »
- 脚本错误:请求的操作需要提升。知道的进来看一下。
- 把这段code的秒钟、分钟和时钟的个位数变成两位数
- CSDN有高手吗?
- ActiveXObject("WScript.Shell");出现错误“Automation server can't create object”
- 关于js 正则表达式的解释
- 这样的js写法有没有产生闭包?
- 求!关于 radio 按钮来控制 text 框是否显示的问题?
- 请问怎样将confirm中的中文变成英文?
- <input type=file>中怎样设置过滤器,让他只选择*.txt文件????
- 新手小白超简单问题
- 怎么样JS正则提取字符
- file中如何判断文件是否存在?
<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>
谢谢大家帮忙 ;)