网站首页
无损音乐
高清电影
游戏新闻
动漫资讯
破解资源
站长资源
游戏攻略
javascript父子通信
网络编程 发布日期:2024/10/14 浏览次数:
1
正在浏览:javascript父子通信
<script language="javascript" defer="defer">
var parent =
{
//
say:function ()
{
//
alert("parent_say");
},
alert:function ()
{
//
alert("parent");
this.say();
}
};
//
parent.addChild("child",
{
//
say:function ()
{
//
alert("child_say");
},
alert:function ()
{
//
alert("child");
this.parent.say();
}
}
);
//parent.child.alert();
//parent.alert();
var c = parent.child;
c.alert();
</script>
<script language="javascript">
Object.prototype.addChild=function(oName, obj)
{
eval("var p=this."+oName+"= new Object()");
this[oName]=obj;
this[oName].parent=this;
}
</script>
效果演示:
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
上一篇:
JS获取scrollHeight问题想到的标准问题
下一篇:
如何实现动态删除javascript函数
首页
无损音乐
高清电影
破解资源