onclick事件:鼠标点击某HTML元素所引发的事件。
适用情况:除了base, bdo, br, head, html, iframe, meta, param, script, style, title 这些HTML元素不适用外,其他HTML元素全部适用。
onmouseout事件:鼠标指针移出某HTML元素所引发的事件。
适用情况:除了base, bdo, br, head, html, iframe, meta, param, script, style, title 这些HTML元素不适用外,其他HTML元素全部适用。
onmouseover事件:鼠标指针移入某HTML元素所引发的事件。
适用情况:除了base, bdo, br, head, html, iframe, meta, param, script, style, title 这些HTML元素不适用外,其他HTML元素全部适用。
onload事件:当HTML元素加载完毕后发生的事件
适用情况:只有 body, frame, frameset, iframe, img, input type=“image”, link, script, style这些HTML元素适用,其他HTML元素全不适用。
代码展示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body onload="load()">
<script>
function load(){
document.write("<h1 οnmοuseοut=out() οnmοuseοver=over() οnclick=clicked() style='color:purple'>[mouseout me、mouseover me、click me]</h1>");
}
function out(){
document.write("<h1 style='color:blue'>onmouseout事件已触发执行out方法!</h1>");
}
function over(){
document.write("<h1 style='color:red'>onmouseover事件已触发执行over方法!</h1>");
}
function clicked(){
document.write("<h1 style='color:green'>onclick事件已触发执行clicked方法!</h1>");
}
</script>
</body>
</html>
效果展示: