onblur失去焦点事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function onblurFun() {
console.log("静态注册失去焦点事件");
}
window.onload=function () {
var passwordObj=document.getElementById("password");
passwordObj.onblur=function () {
console.log("动态注册失去焦点事件");
}
}
</script>
</head>
<body>
用户名:<input type="text" onblur="onblurFun()"><br/>
密码:<input id="password" type="text"><br/>
</body>
</html>
onchange内容发生改变事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function onchangeFun() {
alert("男神已经改变了");
}
<!--动态注册onchange事件-->
window.onload=function () {
var selObj = document.getElementById("s01");
selObj.onchange=function () {
alert("男神已经改变了");
}
}
</script>
</head>
<body>
请选择你心中的男神:
<select onchange="onchangeFun()">
<option>---男神---</option>
<option>dog</option>
<option>cat</option>
<option>panda</option>
<option>fish</option>
</select>
请选择你心中的男神:
<select id="s01">
<option>---男神---</option>
<option>dog</option>
<option>cat</option>
<option>panda</option>
<option>fish</option>
</select>
</body>
</html>
onsumbit表单提交事件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript">
function onsubmitFun() {
alert("静态注册表单提交事件---发现不合法");
return false;
}
window.onload=function () {
var formObj = document.getElementById("form01");
formObj.onsubmit=function () {
alert("静态注册表单提交事件---发现不合法");
return false;
}
}
</script>
</head>
<body>
<form action="http://localhost:8080" method="get" onsubmit="return onsubmitFun()">
<input type="submit" value="静态注册">
</form>
<form action="http://localhost:8080" id="form01">
<input type="submit" value="动态注册">
</form>
</body>
</html>