鼠标移动事件
鼠标移动到某位置 onmousemove
鼠标离开时候 onmouseout
鼠标滑过 onmouseover
鼠标点击事件
onclick
ondblclick
加载和卸载
onload
onunload
获取焦点和失去焦点
onfoucs
onblur
键盘事件
按下抬起 onkeyup
改变事件
onchange
控制表单的提交
onsubmit 作用在表单上<form onsubmit="">
值的写法 onsubmit="return run()"
run()必须有返回值,返回true表单可以提交,返回FALSE表单不能提交。没有返回值,默认是提交
run()的逻辑写表单的校验
<form action="table.html" method="post" onsubmit="return run()">
<table border="1" width="60%">
<tr>
<td>输入姓名</td>
<td><input type="text" name="username" id="nameid" onfocus="run1()" /><span id="uspan"></span></td>
</tr>
<tr>
<td>输入密码</td>
<td><input type="password" name="password" id="passwordid" /><span id="pspan"></span></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" name="repassword" id="repasswordid" /><span id="repspan"></span></td>
</tr>
<tr>
<td>输入邮箱</td>
<td><input type="text" name="email" id="emailid" /><span id="espan"></span></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="注册"></td>
</tr>
</table>
</form>
<script type="text/javascript">
function run(){
// 表单校验,必须有返回值
}
</script>
js控制表单提交
如果没有type=“submit”而是普通的type=“button”
<body>
<form name="form1" id="form" onsubmit="return run()">
<table border="1" width="60%">
<tr>
<td>输入姓名</td>
<td><input type="text" name="username" id="nameid" onfocus="run1()" /><span id="uspan"></span></td>
</tr>
<tr>
<td>输入密码</td>
<td><input type="password" name="password" id="passwordid" /><span id="pspan"></span></td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" name="repassword" id="repasswordid" /><span id="repspan"></span></td>
</tr>
<tr>
<td>输入邮箱</td>
<td><input type="text" name="email" id="emailid" /><span id="espan"></span></td>
</tr>
<tr>
<td colspan="2"><input type="button" value="注册" onclick="running()"></td>
</tr>
</table>
</form>
</body>
<script type="text/javascript">
function run(){
//通过id
// var form = document.getElementById("form");
// 通过name
var form = document.form1;
// 提交表单
form.submit();
//提交设置路径
form.action="table.html";
form.method="post";
}
</script>
注意区别以上两种方法