哎,,我也知道IE5会死的了。。已经麻木了。就是这个URL的原码 http://www.lostinet.com/public/VariablesScopeRecursion.html------------------ 首先是函数定义的递归: //construct new Licence for this scope eval(PopupLicence+""); //re construct InnerPopup for recursion eval(InnerPopup+"");然后这里调用的时候 ,InnerPopup已经是内部的第N层了。 //variables scope recursion InnerPopup(node,Command,GetElementScrollX(td)+td.offsetWidth,GetElementScrollY(td)); 上面就是空间的递归点。(哈哈,,空间析构的地方很模糊,也是IE5死的原因)
楼主这么高兴,可惜我学艺不精看不懂,只能恭喜楼主了 Sandwich
搞半天要右键查看哦,搞得我死翘翘了.<BODY> <XML id=oxml> <item> <item text="text1" value="value1"> <item text="text11" value="value11"> <item text="text111" value="value111"/> <item text="text112" value="value112"/> <item text="text113" value="value113"/> <item text="text114" value="value114"/> </item> <item text="text12" value="value12"> <item text="text121" value="value121"/> <item text="text122" value="value122"/> <item text="text123" value="value123"/> <item text="text124" value="value124"/> </item> <item text="text13" value="value13"> <item text="text131" value="value131"/> <item text="text132" value="value132"/> <item text="text133" value="value133"/> <item text="text134" value="value134"/> </item> <item text="text14" value="value14"> <item text="text141" value="value141"/> <item text="text142" value="value142"/> <item text="text143" value="value143"/> <item text="text144" value="value144"/> </item> </item> <item text="text2" value="value2"> <item text="text21" value="value21"> <item text="text211" value="value211"/> <item text="text212" value="value212"/> <item text="text213" value="value213"/> <item text="text214" value="value214"/> </item> <item text="text22" value="value22"> <item text="text221" value="value221"/> <item text="text222" value="value222"/> <item text="text223" value="value223"/> <item text="text224" value="value224"/> </item> <item text="text23" value="value23"> <item text="text231" value="value231"/> <item text="text232" value="value232"/> <item text="text233" value="value233"/> <item text="text234" value="value234"/> </item> <item text="text24" value="value24"> <item text="text241" value="value241"/> <item text="text242" value="value242"/> <item text="text243" value="value243"/> <item text="text244" value="value244"/> </item> </item> </item> </XML> </BODY> <SCRIPT>//allocate a zindex for popup~ function ZIndexAllocator() { var zindex=100; var fs=new function(){return this.constructor.caller}();//fs=arguments.callee if(fs.Instance)return fs.Instance; return new Singleton(); function Singleton(){fs.Instance=this;} function Singleton.prototype.Alloc() { return zindex++; } }//one scope can have one PopupLicence almost; function PopupLicence() { var delegateCurrent=null; var fs=new function(){return this.constructor.caller}();//fs=arguments.callee //return prevInstance if(fs.Instance)return fs.Instance; //first call return new Singleton(); function Singleton(){fs.Instance=this;} function Singleton.prototype.LicencedTo(delegateRelease) { if(typeof(delegateRelease)=="undefined")throw(new Error(-1,'PopupLicence:LicencedTo Arguments')); LicencedTo(delegateRelease); } function Singleton.prototype.Retract() { Retract(); } function LicencedTo(delegateRelease) { Retract(); delegateCurrent=delegateRelease; } //call delegateRelease to release the object who own the licence function Retract() { if(delegateCurrent) { try { delegateCurrent(); }catch(x){} } delegateCurrent=null; } } function RetractPopupLicence() { new PopupLicence().Retract(); } document.attachEvent("onclick",RetractPopupLicence);//comment point out that the infotext is hidden when the PopupNode fired //document.attachEvent("oncontextmenu",RetractPopupLicence);</SCRIPT> <a href="http://www.lostinet.com" onmouseout="HideTip();" onmouseover="ShowTip(this,"Welcome To Lostinet.com!")">http://www.lostinet.com</a><SCRIPT>function HideTip() { new PopupLicence().Retract(); }function ShowTip(e,msg) { var div=document.createElement("div"); with(div.runtimeStyle) { zIndex=new ZIndexAllocator().Alloc(); padding="4px"; borderWidth="1px"; borderStyle="outset"; borderColor="gray"; position="absolute"; filter="alpha(opacity=80)"; backgroundColor="infobackground"; color="infotext"; pixelLeft=GetElementScrollX(e)+10; pixelTop=GetElementScrollY(e)+e.offsetHeight+10; } div.innerText=msg; document.body.insertAdjacentElement("beforeend",div); e=null; msg=""; //get the licence accoding to current scope new PopupLicence().LicencedTo(OnRelease); function OnRelease() { div.removeNode(true); DestroyScope(); } function DestroyScope() { div=null; pl=null; } function GetElementScrollX(e) { var l=e.offsetLeft; while(e=e.offsetParent)l+=e.offsetLeft; return l; } function GetElementScrollY(e) { var t=e.offsetTop; while(e=e.offsetParent)t+=e.offsetTop; return t; } }</SCRIPT>please right click the body
<SCRIPT>document.body.attachEvent("oncontextmenu",PopupXML);//use PopupNode to popup a menu relate to <xml id=oxml /> function PopupXML() { PopupNode(oxml.documentElement,OnNodeCommand,document.body.scrollLeft+event.clientX,document.body.scrollTop+event.clientY); event.cancelBubble=true; return event.returnValue=false; }//when my menu click function OnNodeCommand(node) { alert(node.getAttribute("value")); }//popup xml menu function PopupNode(node,Command,scrollX,scrollY) { var GlobalPopupLicence=new PopupLicence(); var PopupNode=new function(){return this.constructor.caller}(); InnerPopup(node,Command,scrollX,scrollY); //InnerPopup is for recursion function InnerPopup(node,Command,scrollX,scrollY) { var table=document.createElement("table"); with(table) { with(runtimeStyle) { zIndex=new ZIndexAllocator().Alloc(); borderCollapse="collapse"; borderWidth="1px"; borderStyle="solid"; borderColor="gray"; backgroundColor="white"; position="absolute"; pixelLeft=scrollX; pixelTop=scrollY; } table.border=1; table.borderColor="gray"; } var nodes=node.selectNodes("*"); var nodeChild,tr,td; for(var i=0;i<nodes.length;i++) { nodeChild=nodes.item(i); tr=table.insertRow(); td=tr.insertCell(); td.attachEvent("onmouseover",Delegate_OnOver(nodeChild,td.uniqueID)); td.attachEvent("onmouseout",Delegate_OnOut(nodeChild,td.uniqueID)); td.attachEvent("onclick",Delegate_OnClick(nodeChild,td.uniqueID)); td.innerText=nodeChild.getAttribute("text"); td.runtimeStyle.cursor="hand"; } nodes=null; nodeChild=null; tr=null; td=null; document.body.insertAdjacentElement("beforeend",table); //get Licence of parent scope var pl=new PopupLicence(); pl.LicencedTo(OnRelease); //construct new Licence for this scope eval(PopupLicence+""); //re construct InnerPopup for recursion eval(InnerPopup+""); //construct new scope for new licnece var tcs=TipControlScope(); function TipControlScope() { //new licence,and function eval(PopupLicence+""); eval(ShowTip+""); eval(HideTip+""); return {ShowTip:ShowTip,HideTip:HideTip}; } function Delegate_OnOver(node,uid) { return OnOver; function OnOver() { var td=document.getElementById(uid); if(td.contains(event.fromElement))return; td.runtimeStyle.backgroundColor="orange"; if(node.selectNodes("*").length) { //variables scope recursion InnerPopup(node,Command,GetElementScrollX(td)+td.offsetWidth,GetElementScrollY(td)); } tcs.ShowTip(td,node.getAttribute("value")); } } function Delegate_OnOut(node,uid) { return OnOut; function OnOut() { var td=document.getElementById(uid); if(td.contains(event.toElement))return; td.runtimeStyle.backgroundColor=""; tcs.HideTip(); } } function Delegate_OnClick(node,uid) { return OnClick; function OnClick() { var cmd=Command; var td=document.getElementById(uid); GlobalPopupLicence.Retract(); cmd(node); } } function OnRelease() { tcs.HideTip(); //remove child scope-not the "var pl" new PopupLicence().Retract(); table.removeNode(true); DestroyScope(); } function DestroyScope() { Command=null; table=null; pl=null; tcs=null; } } function GetElementScrollX(e) { var l=e.offsetLeft; while(e=e.offsetParent)l+=e.offsetLeft; return l; } function GetElementScrollY(e) { var t=e.offsetTop; while(e=e.offsetParent)t+=e.offsetTop; return t; } } </SCRIPT>
http://www.lostinet.com/test.asp
http://www.lostinet.com/public/VariablesScopeRecursion.html------------------
首先是函数定义的递归:
//construct new Licence for this scope
eval(PopupLicence+"");
//re construct InnerPopup for recursion
eval(InnerPopup+"");然后这里调用的时候 ,InnerPopup已经是内部的第N层了。
//variables scope recursion
InnerPopup(node,Command,GetElementScrollX(td)+td.offsetWidth,GetElementScrollY(td));
上面就是空间的递归点。(哈哈,,空间析构的地方很模糊,也是IE5死的原因)
Sandwich
<XML id=oxml>
<item>
<item text="text1" value="value1">
<item text="text11" value="value11">
<item text="text111" value="value111"/>
<item text="text112" value="value112"/>
<item text="text113" value="value113"/>
<item text="text114" value="value114"/>
</item>
<item text="text12" value="value12">
<item text="text121" value="value121"/>
<item text="text122" value="value122"/>
<item text="text123" value="value123"/>
<item text="text124" value="value124"/>
</item>
<item text="text13" value="value13">
<item text="text131" value="value131"/>
<item text="text132" value="value132"/>
<item text="text133" value="value133"/>
<item text="text134" value="value134"/>
</item>
<item text="text14" value="value14">
<item text="text141" value="value141"/>
<item text="text142" value="value142"/>
<item text="text143" value="value143"/>
<item text="text144" value="value144"/>
</item>
</item>
<item text="text2" value="value2">
<item text="text21" value="value21">
<item text="text211" value="value211"/>
<item text="text212" value="value212"/>
<item text="text213" value="value213"/>
<item text="text214" value="value214"/>
</item>
<item text="text22" value="value22">
<item text="text221" value="value221"/>
<item text="text222" value="value222"/>
<item text="text223" value="value223"/>
<item text="text224" value="value224"/>
</item>
<item text="text23" value="value23">
<item text="text231" value="value231"/>
<item text="text232" value="value232"/>
<item text="text233" value="value233"/>
<item text="text234" value="value234"/>
</item>
<item text="text24" value="value24">
<item text="text241" value="value241"/>
<item text="text242" value="value242"/>
<item text="text243" value="value243"/>
<item text="text244" value="value244"/>
</item>
</item>
</item>
</XML>
</BODY>
<SCRIPT>//allocate a zindex for popup~
function ZIndexAllocator()
{
var zindex=100;
var fs=new function(){return this.constructor.caller}();//fs=arguments.callee
if(fs.Instance)return fs.Instance;
return new Singleton();
function Singleton(){fs.Instance=this;}
function Singleton.prototype.Alloc()
{
return zindex++;
}
}//one scope can have one PopupLicence almost;
function PopupLicence()
{
var delegateCurrent=null;
var fs=new function(){return this.constructor.caller}();//fs=arguments.callee
//return prevInstance
if(fs.Instance)return fs.Instance;
//first call
return new Singleton();
function Singleton(){fs.Instance=this;}
function Singleton.prototype.LicencedTo(delegateRelease)
{
if(typeof(delegateRelease)=="undefined")throw(new Error(-1,'PopupLicence:LicencedTo Arguments'));
LicencedTo(delegateRelease);
}
function Singleton.prototype.Retract()
{
Retract();
} function LicencedTo(delegateRelease)
{
Retract();
delegateCurrent=delegateRelease;
}
//call delegateRelease to release the object who own the licence
function Retract()
{
if(delegateCurrent)
{
try
{
delegateCurrent();
}catch(x){}
}
delegateCurrent=null;
}
}
function RetractPopupLicence()
{
new PopupLicence().Retract();
}
document.attachEvent("onclick",RetractPopupLicence);//comment point out that the infotext is hidden when the PopupNode fired
//document.attachEvent("oncontextmenu",RetractPopupLicence);</SCRIPT>
<a href="http://www.lostinet.com" onmouseout="HideTip();" onmouseover="ShowTip(this,"Welcome To Lostinet.com!")">http://www.lostinet.com</a><SCRIPT>function HideTip()
{
new PopupLicence().Retract();
}function ShowTip(e,msg)
{
var div=document.createElement("div");
with(div.runtimeStyle)
{
zIndex=new ZIndexAllocator().Alloc();
padding="4px";
borderWidth="1px";
borderStyle="outset";
borderColor="gray";
position="absolute";
filter="alpha(opacity=80)";
backgroundColor="infobackground";
color="infotext";
pixelLeft=GetElementScrollX(e)+10;
pixelTop=GetElementScrollY(e)+e.offsetHeight+10;
}
div.innerText=msg;
document.body.insertAdjacentElement("beforeend",div); e=null;
msg=""; //get the licence accoding to current scope
new PopupLicence().LicencedTo(OnRelease); function OnRelease()
{
div.removeNode(true);
DestroyScope();
}
function DestroyScope()
{
div=null;
pl=null;
}
function GetElementScrollX(e)
{
var l=e.offsetLeft;
while(e=e.offsetParent)l+=e.offsetLeft;
return l;
}
function GetElementScrollY(e)
{
var t=e.offsetTop;
while(e=e.offsetParent)t+=e.offsetTop;
return t;
}
}</SCRIPT>please right click the body
function PopupXML()
{
PopupNode(oxml.documentElement,OnNodeCommand,document.body.scrollLeft+event.clientX,document.body.scrollTop+event.clientY);
event.cancelBubble=true;
return event.returnValue=false;
}//when my menu click
function OnNodeCommand(node)
{
alert(node.getAttribute("value"));
}//popup xml menu
function PopupNode(node,Command,scrollX,scrollY)
{
var GlobalPopupLicence=new PopupLicence();
var PopupNode=new function(){return this.constructor.caller}();
InnerPopup(node,Command,scrollX,scrollY);
//InnerPopup is for recursion
function InnerPopup(node,Command,scrollX,scrollY)
{
var table=document.createElement("table");
with(table)
{
with(runtimeStyle)
{
zIndex=new ZIndexAllocator().Alloc();
borderCollapse="collapse";
borderWidth="1px";
borderStyle="solid";
borderColor="gray";
backgroundColor="white";
position="absolute";
pixelLeft=scrollX;
pixelTop=scrollY;
}
table.border=1;
table.borderColor="gray";
} var nodes=node.selectNodes("*");
var nodeChild,tr,td;
for(var i=0;i<nodes.length;i++)
{
nodeChild=nodes.item(i);
tr=table.insertRow();
td=tr.insertCell();
td.attachEvent("onmouseover",Delegate_OnOver(nodeChild,td.uniqueID));
td.attachEvent("onmouseout",Delegate_OnOut(nodeChild,td.uniqueID));
td.attachEvent("onclick",Delegate_OnClick(nodeChild,td.uniqueID));
td.innerText=nodeChild.getAttribute("text");
td.runtimeStyle.cursor="hand";
}
nodes=null;
nodeChild=null;
tr=null;
td=null; document.body.insertAdjacentElement("beforeend",table); //get Licence of parent scope
var pl=new PopupLicence();
pl.LicencedTo(OnRelease); //construct new Licence for this scope
eval(PopupLicence+""); //re construct InnerPopup for recursion
eval(InnerPopup+""); //construct new scope for new licnece
var tcs=TipControlScope(); function TipControlScope()
{
//new licence,and function
eval(PopupLicence+"");
eval(ShowTip+"");
eval(HideTip+"");
return {ShowTip:ShowTip,HideTip:HideTip};
} function Delegate_OnOver(node,uid)
{
return OnOver;
function OnOver()
{
var td=document.getElementById(uid);
if(td.contains(event.fromElement))return;
td.runtimeStyle.backgroundColor="orange";
if(node.selectNodes("*").length)
{
//variables scope recursion
InnerPopup(node,Command,GetElementScrollX(td)+td.offsetWidth,GetElementScrollY(td));
}
tcs.ShowTip(td,node.getAttribute("value"));
}
}
function Delegate_OnOut(node,uid)
{
return OnOut;
function OnOut()
{
var td=document.getElementById(uid);
if(td.contains(event.toElement))return;
td.runtimeStyle.backgroundColor="";
tcs.HideTip();
}
}
function Delegate_OnClick(node,uid)
{
return OnClick;
function OnClick()
{
var cmd=Command;
var td=document.getElementById(uid);
GlobalPopupLicence.Retract();
cmd(node);
}
}
function OnRelease()
{
tcs.HideTip();
//remove child scope-not the "var pl"
new PopupLicence().Retract();
table.removeNode(true);
DestroyScope();
}
function DestroyScope()
{
Command=null;
table=null;
pl=null;
tcs=null;
}
} function GetElementScrollX(e)
{
var l=e.offsetLeft;
while(e=e.offsetParent)l+=e.offsetLeft;
return l;
}
function GetElementScrollY(e)
{
var t=e.offsetTop;
while(e=e.offsetParent)t+=e.offsetTop;
return t;
}
}
</SCRIPT>
做成菜单也是因为想不到有什么好做
{
new PopupLicence().Retract();
}
document.attachEvent("onclick",RetractPopupLicence);