标签:
<!DOCTYPE>
<html>
<head>
<title> new document </title>
</head>
<body>
<div id="div1">aaa </div>
<div id="div2">bbb </div>
<div id="div3">ccc </div>
</body>
<script type="text/javascript">
function clickEvent(id,callback){
var boxDom = document.getElementById(id);
boxDom.onclick=function(){
if(callback){
//通过参数将当前的dom元素返回出去
callback(this);
};
};
};
clickEvent("div1",function(dom){
dom.style.color = "red";
});
clickEvent("div2",function(dom){
dom.style.fontSize = "60px";
});
clickEvent("div3",function(dom){
dom.style.color = "red";
});
</script>
</html>
标签:
原文地址:http://www.cnblogs.com/c2603/p/5037731.html