onload、onunload()、onchange()、 onmouseover和onmouseout和onmouseup和onmousedown

onload()事件和onunload()事件:

都是需要浏览器加载完后触发,

onload()是用户进入页面时调用。

onunload()是用户离开页面时调用。

onchange()一般用于用户表单中input,

例子:当用户输入字母时将小写字母转化为大写字母

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<script>
function myFunction(){
	var x=document.getElementById("fname");
	x.value=x.value.toUpperCase();
	}
</script>
<input type="text" id="fname" onchange="myFunction()" />
</body>
</html>

  onmouseover和onmouseout和onmouseup和onmousedown

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
div{
	background-color:#F00;
	color:#0C6;
	width:200px;
	height:200px;
	font-size:24px;
	text-align:center;
	font-family:"Lucida Console", Monaco, monospace;
}
</style>
</head>

<body>
<div onMouseOver="mOver(this)" onMouseOut="mOut(this)" onMouseDown="mDown(this)" onMouseUp="onUp(this)">你好</div>
<script>
function mOver(id){
	id.innerHTML="谢谢"
	}
function mOut(id){
	id.innerHTML="拜拜喽"
	}
	function mDown(id){
		id.innerHTML="别碰我"
		}
function onUp(id){
	id.innerHTML="好!不碰你"
	}	
</script>
</body>
</html>

  

 

posted @ 2017-03-26 21:13  943987243  阅读(547)  评论(0编辑  收藏  举报