关于javascript如何向事件绑定函数传递参数
<!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=utf-8" />
<title>如何向事件绑定函数传递参数??</title>
<script language="javascript">
function onload(){
var Item = document.getElementById("MM");
Item.onmousemove = fn; //问题在这!!!请教: 这里如何向fn函数传递参数而又不会让事件失效????????
}
var fn = function(e){ //摸一摸两百多,我这里放一个参数e来收钱,一旦你摸到我你必须得给我钱(传参数),不然我不让你玩,哼..
if(e == undefined){
alert("你这色鬼,不给钱也想玩?滚!!");
return false;
}else{
alert("我是很美很害羞的MM,你摸到我啦!谢谢你给我"+e+"块钱");
}
}
</script>
</head>
<body onload="onload();" >
<div id="MM" style="width:400px; height:250px; background:#060; color:#FFF; margin:0 auto; text-align:center;">我是很美丽很害羞的MM,你摸摸我看看..</div>
</body>
</html>
[解决办法]
Item.onmousemove = function(e){fn(e)};
发这么多帖,我都回回混分~