console
function alertSecond (){
alert("2")
}
function changeco(){
this.style.color="red"
}
function changecoback(){
if(this.style.color=="red"){
this.style.color="black"
}else{
this.style.color="red"
}
}
function changeBackgroundColor() {
console.log(this.textContent);
if (this.style.backgroundColor == "lightskyblue") {
this.style.backgroundColor = "white";
}
else {
this.style.backgroundColor = "lightskyblue";
}
}
function changeColorAndBackgroundColor() {
if (this.style.color == "red") {
this.style.color = "black";
}
else {
this.style.color = "red";
}
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("第3次");
};
var oBtn = document.getElementById("listenbtn");
oBtn.addEventListener("click",function(){
alert("第一次");},false);
oBtn.addEventListener("click",alertSecond,false);
var ocontent =document.getElementById("content")
ocontent .onclick=function(){
ocontent.addEventListener("click",changeco,false)
ocontent.addEventListener("click",changecoback,false)
}
var rebutton =document.getElementById("rebutton")
rebutton.addEventListener("click",function(){
ocontent.removeEventListener("click",changeco,false)
},false)
var ocontent1 =document.getElementById("content1")
ocontent1 .onclick=changeco;
var rebutton1 =document.getElementById("rebutton1")
rebutton1.addEventListener("click",function(){ocontent1.onclick=null;
},false)
document.addEventListener("keydown", function(event) {
console.log(event.type);
if (event.shiftKey || event.altKey || event.ctrlKey){
console.log("你按下啦 shift, alt 或者ctrl");
}
console.log("你按下啦 " + event.keyCode);
}, false);
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="按钮"/>
</br>
</br>
<input id="listenbtn" type="button" value="监听按钮"/>
<div>
<p id="content">广州新华学院</p>
</br>
<button id="rebutton">解除</button>
</div>
<div>
<p id="content1">信息科学学院</p>
</br>
<button id="rebutton1">解除</button>
</div>
</body>
</html>