关于给src赋值时造成的浏览器死掉的问题

yifuzhiming 2014-07-05 11:24:04
我一个定时器不停的调用以下代码,造成浏览器内存消耗很大,时间一长浏览器就死掉了,请问有什么办法可以优化的吗,谢谢大家



for(var i = 1; i < 7; i++)
{
if (i != json.Out1VSoure)
{
document.getElementById("imgAV"+i+"_1").src = "image/b-1.png";
}
if (i != json.Out2VSoure)
{
document.getElementById("imgAV"+i+"_2").src = "image/b-2.png";
}
if (i != json.Out3VSoure)
{
document.getElementById("imgAV"+i+"_3").src = "image/b-3.png";
}
if (i != json.Out4VSoure)
{
document.getElementById("imgAV"+i+"_4").src = "image/b-4.png";
}
}

document.getElementById("imgAV"+json.Out1VSoure+"_1").src = "image/g-1.png";
document.getElementById("imgAV"+json.Out2VSoure+"_2").src = "image/g-2.png";
document.getElementById("imgAV"+json.Out3VSoure+"_3").src = "image/g-3.png";
document.getElementById("imgAV"+json.Out4VSoure+"_4").src = "image/g-4.png";

for(var i = 1; i < 7; i++)
{
if (i != json.Out1ASoure)
{
document.getElementById("imgA"+i+"_1").src = "image/b-1.png";
}
if (i != json.Out2ASoure)
{
document.getElementById("imgA"+i+"_2").src = "image/b-2.png";
}
if (i != json.Out3ASoure)
{
document.getElementById("imgA"+i+"_3").src = "image/b-3.png";
}
if (i != json.Out4ASoure)
{
document.getElementById("imgA"+i+"_4").src = "image/b-4.png";
}
}

document.getElementById("imgA"+json.Out1ASoure+"_1").src = "image/g-1.png";
document.getElementById("imgA"+json.Out2ASoure+"_2").src = "image/g-2.png";
document.getElementById("imgA"+json.Out3ASoure+"_3").src = "image/g-3.png";
document.getElementById("imgA"+json.Out4ASoure+"_4").src = "image/g-4.png";

for(var i = 1; i < 7; i++)
{
if (i != json.Out1VSoure)
{
document.getElementById("imgV"+i+"_1").src = "image/b-1.png";
//$("#imgV"+i+"_1").attr("src","image/b-1.png");
}
if (i != json.Out2VSoure)
{
document.getElementById("imgV"+i+"_2").src = "image/b-2.png";
//$("#imgV"+i+"_2").attr("src","image/b-2.png");
}
if (i != json.Out3VSoure)
{
document.getElementById("imgV"+i+"_3").src = "image/b-3.png";
}
if (i != json.Out4VSoure)
{
document.getElementById("imgV"+i+"_4").src = "image/b-4.png";
}
}
document.getElementById("imgV"+json.Out1VSoure+"_1").src = "image/g-1.png";
document.getElementById("imgV"+json.Out2VSoure+"_2").src = "image/g-2.png";
document.getElementById("imgV"+json.Out3VSoure+"_3").src = "image/g-3.png";
document.getElementById("imgV"+json.Out4VSoure+"_4").src = "image/g-4.png";

...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
万玩完顽完 2014-07-07
  • 打赏
  • 举报
回复
这个怎么会写到内存中呢?
KK3K2005 2014-07-07
  • 打赏
  • 举报
回复
不停的重置 图片src的原因是什么?

87,904

社区成员

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

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