console
window.onload = function(){
var oBtn = document.getElementById("btn");
oBtn.onclick = function() {
alert("欢迎您!");
}
var oDivBtn = document.getElementById("divBtn");
oDivBtn.onclick = function() {
alert("我不是按钮!");
}
var oPContent = document.getElementById("content");
oPContent.onmouseover = function() {
this.style.color = "red";
}
oPContent.onmouseout = function() {
this.style.color = "black";
}
var oUpdownBtn = document.getElementById("updown");
oUpdownBtn.onmousedown = function() {
oPContent.style.color = "blue";
}
oUpdownBtn.onmouseup = function() {
oPContent.style.color = "black";
}
oUpdownBtn.onmousemove = function(){
this.style.backgroundColor = "lightskyblue";
}
var oString = document.getElementById("string");
var oLength = document.getElementById("length");
oString.onkeyup = function() {
var str = oString.value;
oLength.innerHTML = str.length;
}
var oNumber = document.getElementById("number");
var oHint= document.getElementById("hint");
oNumber.onkeyup = function() {
var regex=/^[0-9]*$/;
if (regex.test(oNumber.value)) {
oHint.innerHTML = "输入正确";
oHint.style.color = "green";
}
else {
oHint.innerHTML = "必须输入数字";
oHint.style.color = "red";
}
}
}
function alertMes() {
alert("新华学院");
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
</style>
<script>
</script>
</head>
<body>
<button onclick="alertMes()">弹出信息</button>
<br />
<br />
<button id="btn">弹出欢迎信息</button>
<br />
<br />
<div id="divBtn">点我</div>
<br />
<br />
<div>
<p id="content">广州新华学院</p>
<button id="updown">按下松开</button>
</div>
<div>
<label>输入任意字符:</label>
<input type="text" id="string"></input>
<br />
<label>字符串长度为:</label>
<span id="length">0</span>
</div>
<br/>
<div>
<label>输入数字:</label>
<input type="text" id="number"></input>
<br/>
<div id="hint"></div>
</div>
<br/>
</body>
</html>
#divBtn {
display: inline-block;
width: 80px;
height: 24px;
line-height: 24px;
font-family:微软雅黑;
font-size:15px;
text-align: center;
border-radius: 3px;
background-color: deepskyblue;
color: White;
cursor: pointer;
}