87,914
社区成员
发帖
与我相关
我的任务
分享
function init() {
var el = document.getElementById('MyElement');
el.onclick = function () {……}
}
init();
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title></title>
<style>
div{width:100px;height:20px;border:1px solid black;margin:1px;}
</style>
</head>
<body>
<div id='div'></div>
<div id='div1'></div>
<script type="text/javascript">
document.getElementById('div').onclick=function(){
var a={};
for(var i=0;i<100000;i++)a[i+'']='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
document.getElementById('div1').onclick=function(){};
};
</script>
</body>
</html>
<html>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<body>
<div>
<input type="button" value="aaaa">
<br>
<input type="button" value="bbbb" id="MyElement">
</div>
<SCRIPT type="text/javascript">
function init() {
var el = document.getElementById('MyElement');
el.onclick = function () {alert('haha');};
}
init();
</SCRIPT>
</body>
</html>
function init() {
var el = document.getElementById('MyElement');
var a=1;
var tmp=function(){alert(a)};
el.onclick = tmp;
}
init();