100分相送!超级难题!javascrip的Bug??????请孟兄帮忙解答!

zlps 2002-09-25 10:30:22
关于Tabpane页的动态增加和删除!因为Tabpane页的各个页实际都放在一个页面中,他们仅是该页面中一个层(Div);
当我的Tabpane页不断增加(实际是Div的增加)在Div中我要独立显示一个文件(IFrame src=XXX).问题是当增加时,系统内存数不断增加,而删除该层后,内存没有任何变化,反复操作几次后,内存高达几百兆。请各位大侠帮我解决删除层后,释放该层所占用的内存空间!
...全文
86 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
gu_xin2002 2002-09-28
  • 打赏
  • 举报
回复
有没有考虑用XML数据绑定???
也许比较容易实现
zlps 2002-09-27
  • 打赏
  • 举报
回复
首先iframe肯定占有内存!
innerHTML="" 还是没有释放内存!困扰我的问题,还是没有解决。
ccton 2002-09-26
  • 打赏
  • 举报
回复
那你就不要删除嘛,覆盖.
zlps 2002-09-26
  • 打赏
  • 举报
回复
我的层的确已经删除(通过alert(outerHTML))
llrock 2002-09-26
  • 打赏
  • 举报
回复
你用上面的yourdiv.innerHTML='';方法删除试试看,我觉得浏览器顶多把iframe中的信息缓冲到了硬盘,不是在内存(不是映像)中.
yonghengdizhen 2002-09-26
  • 打赏
  • 举报
回复
iframe复用..

而不要新建iframe.

mybios 2002-09-25
  • 打赏
  • 举报
回复
DIV的删除方法是
<div id=aaa>sadfsdf</div>
<button onclick="aaa.outerHTML=''">删除</button>
孟子E章 2002-09-25
  • 打赏
  • 举报
回复
你的div是怎么删除的?用什么办法删除的?如果用display,visibility的话,是没有真正的删除
dylanOK 2002-09-25
  • 打赏
  • 举报
回复
把代码帖出来。我们也好看看秋水的方法效果如何。 :)

以前不知道 CollectGarbage 这个东西……
zlps 2002-09-25
  • 打赏
  • 举报
回复
我的表达能力比较差!抱歉,非常感谢大家的解答,但没有达到要害处!这个问题简单可以这么问:
<html><body>
<div>
<div id="tabpage0">
<h2>tab title1</h2>
<iframe src="test1.htm"/>
</div>
<!--这是第一层-->
<div id="tabpage1">
<h2>tab title2</h2>
<iframe src="test2.htm"/>
</div>
.
.
.
.
</div>
</body></html>
我的层是动态增加、删除。但是每一层要加载iframe,他需要占用内存。但是
删除层后,iframe所占用的内存没有释放!导致反复操作,死机!
我的原初想是:删除一个层如同关闭一个窗口,内存释放!
不知道这样大家能否理解我的问题?
qiushuiwuhen 2002-09-25
  • 打赏
  • 举报
回复
<script>CollectGarbage();</script>
yonghengdizhen 2002-09-25
  • 打赏
  • 举报
回复
帖出代码来.
看看先
flashsoft2000 2002-09-25
  • 打赏
  • 举报
回复
不会呀,代码给出来看看
llrock 2002-09-25
  • 打赏
  • 举报
回复
把你的代码贴出来,你确定是js的错误?
llrock 2002-09-25
  • 打赏
  • 举报
回复
var pages = [];
var selectedIndex = null;
var tabRow;
var TabID=0;;
//Identify式样的字段,记录所有操作过的Tab页的个数,命名采取递增式
function WebFXTabPane( TabDiv) {
this.element = TabDiv;
this.element.tabPane = this;
this.element.className = this.classNameTag + " " + this.element.className;

tabRow = document.createElement( "div" );
tabRow.className = "tab-row";
TabDiv.insertBefore( tabRow, TabDiv.firstChild );
var toolbar = document.createElement("div");
toolbar.setAttribute("id","toolbar");
toolbar.className="toolbar";
toolbar.style.left=parseInt(document.body.clientWidth)-56;
toolbar.onmouseover=this.btnover;
toolbar.onmouseout = this.btnout;
var refreshbtn = document.createElement("button");
refreshbtn.setAttribute("id","refreshbtn");
refreshbtn.onclick=this.refreshTabpage;
refreshbtn.style.backgroundImage="url('images/refresh.gif' )";
toolbar.appendChild(refreshbtn);
var deletebtn = document.createElement("button");
deletebtn.setAttribute("id","deletebtn");
deletebtn.onclick=this.delTabPage;
deletebtn.style.backgroundImage="url('images/delete.gif' )";
toolbar.appendChild(deletebtn);
TabDiv.appendChild(toolbar);
var tabIndex = 0;
this.selectedIndex = tabIndex;
// loop through child nodes and add them
var cs = TabDiv.childNodes;
var n;
for (var i = 0; i < cs.length; i++) {
if (cs[i].nodeType == 1 && cs[i].className == "tab-page")
this.addTabPage( cs[i] );
}
}

WebFXTabPane.prototype = {
classNameTag:"dynamic-tab-pane-control",
setSelectedIndex:function(n){
if (selectedIndex != n) {
if (selectedIndex != null && pages[ selectedIndex ] != null )
pages[ selectedIndex ].hide();
selectedIndex = n;
pages[selectedIndex].show();
}
},
getSelectedIndex:function () {return selectedIndex;},
addTabPage:function (oElement) {
if ( oElement.tabPage == this ) return oElement.tabPage;
var n = pages.length;
TabID ++;
var tp = pages[n] = new WebFXTabPage( oElement, this, n );
tp.tabPane = this;//建立Tabpane和TabPage的联系(协作类)
tabRow.appendChild( tp.tab );
if ( n == selectedIndex ) tp.show();else tp.hide();
this.setSelectedIndex(n);
return tp;
},
delTabPage:function(){
var tmpid= "frame"+pages[selectedIndex].pageID.substring(5);
if(selectedIndex==0) return false;
if(document.all(pages[selectedIndex].pageID)){
document.all(tmpid).src="";
tabRow.removeChild(document.all(pages[selectedIndex].pageID));
document.all("tabpage"+pages[selectedIndex].pageID.substring(5)).removeNode(true);
selectedIndex--;
/*
<-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<------------我猜问题出在这里,我没有看完你的代码,只是根据你的问题猜测应该在这里,
<------------好像是个无法结束的循环,我觉得你应该考虑一下这里,你的循环体改变了循环条件
<-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
for(var i=parseInt(selectedIndex)+1;i<(parseInt(pages.length)-1);i++)

{
pages[i]=pages[i+1];
pages[i+1].index--;
}
pages.length--; }
pages[ selectedIndex].show();

},
refreshTabpage:function(){

var currpageID = pages[selectedIndex].pageID;
var currSrc=document.all("frame"+pages[selectedIndex].pageID.substring(5));
var tmp ;
tmp = currSrc.src;
currSrc.src=tmp;

},
btnover:function(){
oEvent = window.event.srcElement;
if(oEvent.tagName=="BUTTON")
oEvent.style.border="1px solid blue";
},
btnout:function(){
oEvent = window.event.srcElement;
if(oEvent.tagName=="BUTTON")
oEvent.style.border="0px solid blue";
}
};

function WebFXTabPage( el, tabPane, nIndex ) {

this.element = el;
this.element.tabPage = this;
this.index = nIndex;
this.id = el.id;
this.MarkID = el.getAttribute("MarkID")?el.getAttribute("MarkID"):-1;
var cs = el.childNodes;
for (var i = 0; i < cs.length; i++) {
if (cs[i].nodeType == 1 && cs[i].className == "tab") {
this.tab = cs[i];
break;
}
}
// insert a tag around content to support keyboard navigation
var a = document.createElement( "span" );

while ( this.tab.hasChildNodes()){
a.appendChild( this.tab.firstChild);
}
this.tab.appendChild( a );
this.pageID = a.parentNode.id;

// hook up events, using DOM0
var oThis = this;
this.tab.onmousedown= function () { oThis.select(); };
this.tab.onkeydown= function () { if(event.keyCode==9) {oThis.select();}};//按Tab键切换Tab页
//this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); };
//this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };

}

WebFXTabPage.prototype = {
show: function () {
var el = this.tab;
var s = el.className + " selected";
s = s.replace(/ +/g, " ");
el.className = s;
this.element.style.display = "block";
},

hide: function () {
var el = this.tab;
var s = el.className;
s = s.replace(/ selected/g, "");
el.className = s;

this.element.style.display = "none";
},
select: function () {
this.tabPane.setSelectedIndex( this.index);
}
};

WebFXTabPage.tabOver = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className + " hover";
s = s.replace(/ +/g, " ");
el.className = s;

};

WebFXTabPage.tabOut = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className;
s = s.replace(/ hover/g, "");
el.className = s;
};


// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
var all = document.getElementsByTagName( "*" );
var l = all.length;
var tabPaneRe = /tab\-pane/;
var tabPageRe = /tab\-page/;
var cn, el;
var parentTabPane;
for ( var i = 0; i < l; i++ ) {
el = all[i];
cn = el.className;
// no className
if ( cn == "" ) continue;
// uninitiated tab pane
if ( tabPaneRe.test( cn ) && !el.tabPane )
new WebFXTabPane( el );

// unitiated tab page wit a valid tab pane parent
else if ( tabPageRe.test( cn ) && !el.tabPage &&tabPaneRe.test( el.parentNode.className ) ) {
el.parentNode.tabPane.addTabPage( el );
}
}
}
// initialization hook up
if ( typeof window.attachEvent =="object"){
window.attachEvent( "onload", setupAllTabs );
}
function showDetail(oElement){
var showobj = document.all("overDiv");
showobj.innerText=oElement.innerText;
window.status=window.event.clientX;
showobj.style.left=event.clientX+30;
showobj.style.top=event.clientY+20;
showobj.style.visibility="visible";
}
function hideDetail(){
if(document.all("overDiv").style.visibility=="visible")
document.all("overDiv").style.visibility="hidden";
}
yonghengdizhen 2002-09-25
  • 打赏
  • 举报
回复
DIV的删除方法是
<HEAD>
<SCRIPT>
function removeElement()
{
try
{
//The first child of the div is the bold element.
var oChild=Div1.children(0);
Div1.removeChild(oChild);
}
catch(x)
{
alert("You have already removed the bold element.
Page will be refreshed when you click OK.")
document.location.reload();
}
}
</SCRIPT>
</HEAD>
<BODY>
<DIV ID=Div1 onclick="removeElement()">
Click anywhere in this sentence to remove this <B>Bold</B> word.
</DIV>
</BODY>

<SCRIPT>
function fnRemove(){
// 'true' possible value specifies removal of childNodes also
oTable.removeNode(true);
}
</SCRIPT>

<TABLE ID = oTable>
<TR>
<TD>Cell 1</TD>
<TD>Cell 2</TD>
</TR>
</TABLE>

<INPUT TYPE = button VALUE = "Remove Table" onclick = "fnRemove()">
mophi 2002-09-25
  • 打赏
  • 举报
回复
aaa.outerHTML=''
只是清空aaa.outerHTML属性
而aaa还是存在的

什么超级难题?...
mophi 2002-09-25
  • 打赏
  • 举报
回复
<div id=aaa>sadfsdf</div>

<button onclick="bbb=aaa.parentElement;bbb.removeChild(aaa);">删除</button>


zlps 2002-09-25
  • 打赏
  • 举报
回复

/*
* Tab Pane
*/
var pages = [];
var selectedIndex = null;
var tabRow;
var TabID=0;;
//Identify式样的字段,记录所有操作过的Tab页的个数,命名采取递增式
function WebFXTabPane( TabDiv) {
this.element = TabDiv;
this.element.tabPane = this;
this.element.className = this.classNameTag + " " + this.element.className;

tabRow = document.createElement( "div" );
tabRow.className = "tab-row";
TabDiv.insertBefore( tabRow, TabDiv.firstChild );
var toolbar = document.createElement("div");
toolbar.setAttribute("id","toolbar");
toolbar.className="toolbar";
toolbar.style.left=parseInt(document.body.clientWidth)-56;
toolbar.onmouseover=this.btnover;
toolbar.onmouseout = this.btnout;
var refreshbtn = document.createElement("button");
refreshbtn.setAttribute("id","refreshbtn");
refreshbtn.onclick=this.refreshTabpage;
refreshbtn.style.backgroundImage="url('images/refresh.gif' )";
toolbar.appendChild(refreshbtn);
var deletebtn = document.createElement("button");
deletebtn.setAttribute("id","deletebtn");
deletebtn.onclick=this.delTabPage;
deletebtn.style.backgroundImage="url('images/delete.gif' )";
toolbar.appendChild(deletebtn);
TabDiv.appendChild(toolbar);
var tabIndex = 0;
this.selectedIndex = tabIndex;
// loop through child nodes and add them
var cs = TabDiv.childNodes;
var n;
for (var i = 0; i < cs.length; i++) {
if (cs[i].nodeType == 1 && cs[i].className == "tab-page")
this.addTabPage( cs[i] );
}
}

WebFXTabPane.prototype = {
classNameTag:"dynamic-tab-pane-control",
setSelectedIndex:function(n){
if (selectedIndex != n) {
if (selectedIndex != null && pages[ selectedIndex ] != null )
pages[ selectedIndex ].hide();
selectedIndex = n;
pages[selectedIndex].show();
}
},
getSelectedIndex:function () {return selectedIndex;},
addTabPage:function (oElement) {
if ( oElement.tabPage == this ) return oElement.tabPage;
var n = pages.length;
TabID ++;
var tp = pages[n] = new WebFXTabPage( oElement, this, n );
tp.tabPane = this;//建立Tabpane和TabPage的联系(协作类)
tabRow.appendChild( tp.tab );
if ( n == selectedIndex ) tp.show();else tp.hide();
this.setSelectedIndex(n);
return tp;
},
delTabPage:function(){
var tmpid= "frame"+pages[selectedIndex].pageID.substring(5);
if(selectedIndex==0) return false;
if(document.all(pages[selectedIndex].pageID)){
document.all(tmpid).src="";
//alert(tmpid+","+document.all(tmpid).src);
tabRow.removeChild(document.all(pages[selectedIndex].pageID));
document.all("tabpage"+pages[selectedIndex].pageID.substring(5))removeNode(true);
selectedIndex--;
//pages[selectedIndex].index --;
//此处ID需要处理
for(var i=parseInt(selectedIndex)+1;i<(parseInt(pages.length)-1);i++)
{
pages[i]=pages[i+1];
pages[i+1].index--;
}
pages.length--; }
pages[ selectedIndex].show();

},
refreshTabpage:function(){

var currpageID = pages[selectedIndex].pageID;
var currSrc=document.all("frame"+pages[selectedIndex].pageID.substring(5));
var tmp ;
tmp = currSrc.src;
currSrc.src=tmp;

},
btnover:function(){
oEvent = window.event.srcElement;
if(oEvent.tagName=="BUTTON")
oEvent.style.border="1px solid blue";
},
btnout:function(){
oEvent = window.event.srcElement;
if(oEvent.tagName=="BUTTON")
oEvent.style.border="0px solid blue";
}
};

function WebFXTabPage( el, tabPane, nIndex ) {

this.element = el;
this.element.tabPage = this;
this.index = nIndex;
this.id = el.id;
this.MarkID = el.getAttribute("MarkID")?el.getAttribute("MarkID"):-1;
var cs = el.childNodes;
for (var i = 0; i < cs.length; i++) {
if (cs[i].nodeType == 1 && cs[i].className == "tab") {
this.tab = cs[i];
break;
}
}
// insert a tag around content to support keyboard navigation
var a = document.createElement( "span" );

while ( this.tab.hasChildNodes()){
a.appendChild( this.tab.firstChild);
}
this.tab.appendChild( a );
this.pageID = a.parentNode.id;

// hook up events, using DOM0
var oThis = this;
this.tab.onmousedown= function () { oThis.select(); };
this.tab.onkeydown= function () { if(event.keyCode==9) {oThis.select();}};//按Tab键切换Tab页
//this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); };
//this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };

}

WebFXTabPage.prototype = {
show: function () {
var el = this.tab;
var s = el.className + " selected";
s = s.replace(/ +/g, " ");
el.className = s;
this.element.style.display = "block";
},

hide: function () {
var el = this.tab;
var s = el.className;
s = s.replace(/ selected/g, "");
el.className = s;

this.element.style.display = "none";
},
select: function () {
this.tabPane.setSelectedIndex( this.index);
}
};

WebFXTabPage.tabOver = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className + " hover";
s = s.replace(/ +/g, " ");
el.className = s;

};

WebFXTabPage.tabOut = function ( tabpage ) {
var el = tabpage.tab;
var s = el.className;
s = s.replace(/ hover/g, "");
el.className = s;
};


// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
var all = document.getElementsByTagName( "*" );
var l = all.length;
var tabPaneRe = /tab\-pane/;
var tabPageRe = /tab\-page/;
var cn, el;
var parentTabPane;
for ( var i = 0; i < l; i++ ) {
el = all[i];
cn = el.className;
// no className
if ( cn == "" ) continue;
// uninitiated tab pane
if ( tabPaneRe.test( cn ) && !el.tabPane )
new WebFXTabPane( el );

// unitiated tab page wit a valid tab pane parent
else if ( tabPageRe.test( cn ) && !el.tabPage &&tabPaneRe.test( el.parentNode.className ) ) {
el.parentNode.tabPane.addTabPage( el );
}
}
}
// initialization hook up
if ( typeof window.attachEvent =="object"){
window.attachEvent( "onload", setupAllTabs );
}
function showDetail(oElement){
var showobj = document.all("overDiv");
showobj.innerText=oElement.innerText;
window.status=window.event.clientX;
showobj.style.left=event.clientX+30;
showobj.style.top=event.clientY+20;
showobj.style.visibility="visible";
}
function hideDetail(){
if(document.all("overDiv").style.visibility=="visible")
document.all("overDiv").style.visibility="hidden";
}


zlps 2002-09-25
  • 打赏
  • 举报
回复
<html>
<head>
<title>客户区</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link id="luna-tab-style-sheet" type="text/css" rel="stylesheet" href="tab.css" />
<style type="text/css">

html, body {
background: ThreeDFace;
}
</style>
<script type="text/javascript" src="js/tabpane.js"></script>
</head>
<body onresize="resizetoolbar();">
<div ID="overDiv" style="position: absolute; visibility: hidden; z-index:400; left:0; top: 0; height:19;font-size:9pt;background:rgb(214,223,239);"></div>
<div class="tab-pane" id="tabPane1" style="height:100%">
<div class="tab-page" id="tabPage0" MarkID="homepage">
<h2 class="tab" tabIndex=0 id="index0">主页</h2>
<div id="divContent" >
<IFRAME SRC="uitest/HomePage.htm" ID="frame0" frameborder=0 STYLE="margin:0px;height:100%;left:0px;width:100%; TOP: 0px;"></IFRAME>
</div>
</div>
</div>
<!-- id is not necessary unless you want to support multiple tabs with persistence -->
<script type="text/javascript">

var tp1 = new WebFXTabPane(document.all( "tabPane1" ));
//tp1.setSelectedIndex(0);
var detailwin;
function appendTabPage(name,src,id){
var NewTabID = "tabPage"+TabID;
var isExist = false;
for(var i=0;i<pages.length;i++)
{
if(id==pages[i].MarkID)
{
pages[i].tabPane.setSelectedIndex(i);
isExist = true;
}

} //判断页面是否存在,如果存在则置为焦点,反之增加
if(!isExist){
var sHTML = '<div class="tab-page" id="'+NewTabID+'" MarkID="'+id+'" > '+
'<h2 onmouseover="showDetail(this);" onmouseout="hideDetail()" class="tab" tabIndex='+TabID+' id="index'+TabID+'">'+name+'</h2>'
+'<IFRAME SRC="'+src+'" ID="frame'+TabID+'" frameborder=0 STYLE="margin:0px;height:100%;left:0px;width:100%; TOP: 0px;overflow:hidden"></IFRAME></div>';
document.all("tabPane1").insertAdjacentHTML("beforeEnd",sHTML);
tp1.addTabPage(document.all(NewTabID)) ;
}
}
function resizetoolbar(){
document.all("toolbar").style.left=parseInt(document.body.clientWidth)-56;
}

</script>
</body>
</html>


87,994

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧