JavaScript绑定事件IE(闭包,apply,call)
时间:2010-10-13 来源:codefans
代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JavaScript绑定事件IE(闭包,apply,call)</title>
<script type="text/javascript">
function show()
{
var value=this.value;
return function()
{
alert(value);
}
}
window.onload=function()
{
document.getElementById('Test').attachEvent('onclick',show.apply(document.getElementById('Test')));
}
</script>
</head>
<body>
<input type="button" value="测试" id="Test" onClick="alert('Test')" />
</body>
</html>
相关阅读 更多 +