一般寫事件綁定都是這樣寫的:
document.getElementById('btn').onclick = function() { func... }
現(xiàn)在這樣寫:
<input type="button" id="btn" value="hello"/>
<script language="JavaScript">
<!--
function associate(str){
return (function(e){ // event會(huì)默認(rèn)傳進(jìn)去,所以不用在associate的參數(shù)里傳遞event ( associate(event) )
var _e = e||window.event; // 在這里加入判斷,兼容ff和ie
doClick(_e, this, str);
});
}
function doClick(a, b, c) {
alert(a.type);
alert(b.type);
alert(c);
}
document.getElementById('btn').onclick = associate('hello');
//-->
</script>