JS_常见事件 举例 笔记
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<title>JS_事件</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function t1(){
document.getElementsByTagName('input')[0].style.border='1px solid orange';
}
function t2(){
document.getElementsByTagName('input')[0].style.border='';
}
function t3(){
alert('验证码是不是错了');
return false;
}
function t4(){
document.getElementsByTagName('li')[0].style.fontSize='20px';
}
function t5(){
document.getElementsByTagName('li')[0].style.fontSize='';
}
</script>
</head>
<body>
<h1>常用事件</h1>
<ul>
<li onmouseover="t4();" onmouseleave="t5();">鼠标经过</li>
</ul>
<form action="#" method="get" onsubmit="return t3();">
<p>
用户:<input type="text" name="username" onfocus="t1();" onblur="t2();" />
</p>
<p>
密码:<input type="password" name="password" />
</p>
<p>
<input type="submit" value="提交" />
</p>
</form>
<p>焦点:onfocus</p>
<p>失去焦点:onblur</p>
<p>鼠标经过时:onmouseover</p>
<p>表单提交时:onsubmit</p>
<p>页面加载完毕时:onload</p>
详细的事件可以去W3School里查找
</body>
</html>
Dcr163的博客
http://dcr163.cn/56.html(转载时请注明本文出处及文章链接)