事件
事件 描述
onclick 单击事件
onMouseOver 鼠标经过事件
onMouseOut 鼠标移出事件
onChange 文本内容改变事件
onSelect 文本框选中事件
onFocus 光标聚集事件
onBlur 移开光标事件
onload 页面加载事件
onUnload 关闭网页事件
简单事例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>事件</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script>
function clik() {
alert("被单击了");
}
</script>
<button οnclick="clik()" value="按钮"></button>
<br>
<script>
function mouseOver(over) {
//鼠标经过是div的内容
over.innerHTML="i am smile";
}
function mouseOut(out) {
//鼠标移出时div的内容改变
out.innerHTML="ok i know";
}
</script>
<script>
function change() {
alert("内容改变了");
}
</script>
<div class="div" οnmοuseοver="mouseOver(this)" οnmοuseοut=" mouseOut(this)"></div>
<br>
<form>
<input type="text" οnchange="change()">
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body οnlοad="c()">
<script>
function a(bg) {
bg.style.backgroundColor="red";
}
function b(bg) {
bg.style.backgroundColor="blue";
}
function c() {
alert("页面加载完成")
}
</script>
<form>
<input type="text" οnselect="a(this) " οnfοcus="b(this)">
</form>
</body>
</html>