复制代码 代码如下:
<script language = "javascript" type = "text/javascript">
function test(){
window.alert("你投了一次票");
//解除绑定事件
document.getElementById("but1").removeEventListener("onclick",test);
}
</script>
<body>
<input id = "but1" type = "button" value = "投票" />
<script language = "javascript" type = "text/javascript">
//动态绑定事件 可以取消绑定
document.getElementById("but1").addEventListener("onclick",test);
</script>
</body>
时间: 2024-11-27 23:53:47