javascript父子通信

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

javascript父子通信

  2020-05-12 我要评论
<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需刷新才能执行]

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们