求教 如何捕获显示/隐藏出发的事件 事实上我感觉由于父结点状态变化导致子节点表现变化,似乎是不能通过捕获的,因为子节点的状态是没有变化的,有变化的是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。谢谢大家帮忙 ;) 跪求大神解决!!!!!!!! js form 提交到新窗口 如何将8个同名的CHECKBOX,值是0或1,提交后保存到一个8位的整型上,并且刷新见面后要能根据0或1判断是否选中 遇到一个比较棘手的问题,高手进来看看-- 如何根据不同的判断条件引入不同的html文件 还是抽奖问题-.- 求教页面的转化 js中如何得到jsp页面中的ArrayList的值? 急.......非常简单的问题 怎样使四周紫色边框宽度相等? 怎么样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>
谢谢大家帮忙 ;)