console
function alertSecond()
{
alert("2");
}
function changeColor()
{
if (this.style.color == "red")
{
this.style.color = "black";
}
else {
this.style.color = "red";
}
}
function changeBackgroundColor()
{
if (this.style.backgroundColor == "lightskyblue")
{
this.style.backgroundColor = "white";
}
else
{
this.style.backgroundColor = "lightskyblue";
}
}
window.onload = function ()
{
var oBtn = document.getElementById("btn");
oBtn.onclick = function ()
{
alert("1");
};
oBtn.onclick = function ()
{
alert("2");
};
oBtn.onclick = function ()
{
alert("1");
alert("2");
alert("3");
};
var oBtn = document.getElementById("listenBtn");
oBtn.addEventListener("click", function()
{
alert("1");
}, false);
oBtn.addEventListener("click", alertSecond, false);
oBtn.removeEventListener("click", alertSecond, false);
var oPContent = document.getElementById("content");
oPContent.addEventListener("click", changeColor, false);
oPContent.addEventListener("click", changeBackgroundColor, false);
var oBtn = document.getElementById("removeBtn");
oBtn.addEventListener("click", function()
{
oPContent.removeEventListener("click", changeColor, false);
}, false);
var oPContent1 = document.getElementById("content1");
oPContent1.onclick = changeColor;
var oBtn1 = document.getElementById("removeBtn1");
oBtn1.addEventListener("click", function(event)
{
alert(event.type);
oPContent1.onclick = null;
}, false);
document.addEventListener("keydown", function(event)
{
console.log(event.type);
if (event.shiftKey || event.altKey || event.ctrlKey)
{
console.log("按了shit alt ctrl");
}
console.log("按了 " + event.keyCode);
});
document.addEventListener("keyup", function(event)
{
console.log(event.type);
console.log("松了 " + event.keyCode);
})
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
</script>
</head>
<body>
<input id="btn" type="button" value="111"/>
<br/>
<br/>
<input id="listenBtn" type="button" value="监听"/>
<div>
<p id="content">新年快乐</p>
<button id="removeBtn">解除</button>
</div>
<div>
<p id="content1">五一快乐</p>
<button id="removeBtn1">解除</button>
</div>
</body>
</html>