我是靠谱客的博主 温柔柜子,这篇文章主要介绍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需刷新才能执行]

最后

以上就是温柔柜子最近收集整理的关于javascript父子通信的全部内容,更多相关javascript父子通信内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(165)

评论列表共有 0 条评论

立即
投稿
返回
顶部