<style type="text/css">
*{ margin:0px auto; padding:0px; font-family:微软雅黑; font-size:14px;}
</style>
</head>
<body>
<div id="dd" style="width:200px; height:200px; background-color:#669">
这是一个层
</div>
<span οnclick="add1()">点击挂上事件</span>
<span οnclick="remove1()">点击移除事件</span>
</body>
<script type="text/javascript">
function showdd()
{
alert("被点中了");
}
function add1()
{
var d = document.getElementById("dd");
d.onclick = function (){showdd()}; //匿名函数
}
function remove1()
{
var d = document.getElementById("dd");
d.onclick = function (){}; //空匿名函数
}
</script>
</html>