javascript父子通信
更新時(shí)間:2007年05月27日 00:00:00 作者:
<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需再刷新一下頁面才能執(zhí)行]
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需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
微信小程序天氣預(yù)報(bào)功能實(shí)現(xiàn)(支持自動定位,附源碼)
對于一個(gè)經(jīng)常出門在外的人,關(guān)注天氣是至關(guān)重要的,下面這篇文章主要給大家介紹了關(guān)于微信小程序天氣預(yù)報(bào)功能實(shí)現(xiàn)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),支持自動定位,需要的朋友可以參考下2022-04-04JS+DIV實(shí)現(xiàn)鼠標(biāo)劃過切換層效果的方法
這篇文章主要介紹了JS+DIV實(shí)現(xiàn)鼠標(biāo)劃過切換層效果的方法,涉及javascript鼠標(biāo)事件及頁面元素操作的相關(guān)技巧,需要的朋友可以參考下2015-05-05bootstrap日期插件daterangepicker使用詳解
這篇文章主要為大家詳細(xì)介紹了bootstrap日期插件daterangepicker的使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10基于JS實(shí)現(xiàn)限時(shí)搶購倒計(jì)時(shí)間表代碼
本文給大家分享一段簡單的代碼基于js實(shí)現(xiàn)限時(shí)搶購倒計(jì)時(shí)間表功能,非常不錯,代碼簡單易懂,需要的的朋友參考下吧2017-05-05