/*
* 静态页面要施放因(add)此元素添加事件的内存.
*/
<input id="add" type="button" value="add" />
<input id="det" type="button" value="det" />
<script type="text/javascript">
(function(){
var add = document.getElementById("add");
var det = document.getElementById("det");
/*增加事件*/
~function(){
var str = new Array(1000).join(new Array(5000).join("xxxxx"));
add.onclick = function(){
var arr = [];
arr.push(str);
}
}();
/*移除事件*/
~function(){
det.onclick = function(){
add.onclick = null;
}
}();
})();
</script>
/*
* 动态添加的元素施放内存.
*/
<input id="add" type="button" value="add" />
<input id="det" type="button" value="det" />
<div id="box"></div>
<script type="text/javascript">
(function(){
var add = document.getElementById("add");
var det = document.getElementById("det");
var box = document.getElementById("box");
/*增加事件*/
~function(){
var str = new Array(1000).join(new Array(5000).join("xxxxx"));
add.onclick = function(){
var temp = document.createElement("div");
temp.id = "hello";
temp.className = "hello"
box.appendChild(temp);
temp.onclick = function(){
var arr = [];
arr.push(str);
}
}
}();
/*移除事件*/
~function(){
det.onclick = function(){
document.getElementById("hello").onclick = null;
add.onclick = null;
}
}();
})();
</script>