求教 如何捕获显示/隐藏出发的事件 事实上我感觉由于父结点状态变化导致子节点表现变化,似乎是不能通过捕获的,因为子节点的状态是没有变化的,有变化的是offsetWidth之类的属性,但是这些属性又不能出发propertychange事件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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> 有一个大问题是那个div也不是我能控制的,我没有办法给他增加事件。而且上面的div仅仅是个例子,容器可能是div也可能是其他的标签,我觉得给每个标签增加这样的控制是不适合的。 我现在正在用OPS作xforms的组件扩展,在xforms:switch/xform:case中,OPS会将他变为div,但是我现在不可能控制OPS产生的div(例如给他增加方法属性等),所以没有办法从外部来控制。 我放弃了,这个问题似乎无解,我现在的做法是在xforms:switch触发tab切换时,再调用一边初始化方法。sigh,主要是offsetWidth的原因,不显示的时候这个值总是0。谢谢大家帮忙 ;) javascript的这种语法 请教一个层随滚动条滚动的问题? 有用过FCKeditor控件的朋友进来聊聊. 急,Error:'window.button1.style' 为空或不是对象,如何将代码写规范,帮忙改改不会javascript 正则高手请进, 100分,100分,100分,求JS获取“客户端”的“桌面”位置,高手请进,100分,100分,100分 我想横向打印 怎样用嵌入的iframe中的一个按钮来控制包含这个iframe的页面的刷新事件呢? 给初学者提供几本学习js值得看的书 如何把参数传给新打开的窗体 怎么样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>
谢谢大家帮忙 ;)