
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<p id="div">Hello</p>
<button id="btn" text="" runat="server">按钮</button>
<script type="text/javascript">
//document.getElementById("div").innerHTML = "world";
//方法一:直接添加
document.getElementById("btn").addEventListener("click", function () {
alert(1);
});
//方法二:多个句柄
var x = document.getElementById("btn");
x.addEventListener("click", hello);
x.addEventListener("click", world);
//移除hello事件
x.removeEventListener("click", hello);
function hello() {
alert("Hello");
}
function world() {
alert("world");
}
</script>
</body>
</html>