- 鼠標(biāo)點擊事件:click
- 鼠標(biāo)懸停事件:hover
- 鼠標(biāo)移走事件:mouse out
- 鼠標(biāo)提交事件,觸發(fā)JS函數(shù):onsubmi
- 網(wǎng)頁加載事件:load
- 下拉列表框選項切換事件:change
- 輸入框失去焦點事件:blur
- 輸入框產(chǎn)生焦點事件:fcous
function: 聲明一個函數(shù)的開始
document:相當(dāng)于一個集合
getElemnetById():通過id來取得元素,只能訪問id元素并且調(diào)用
innerHTML:獲取對象的內(nèi)容或者向?qū)ο蟛迦雰?nèi)容
onblur:在對象失去焦點的時候會觸發(fā)onblur事件
span:內(nèi)部元素,行內(nèi)元素文本的容器
alert():彈出警告框
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
function checkuser(username) {
if(username==null||username==""){
document.getElementById("user_error").innerHTML="*用戶名不能為空";
return false;
}else{
document.getElementById("user_error").innerHTML="";
return true;
}
}
function checkpwd (passwords) {
if(passwords==null||passwords==""){
document.getElementById("pwd_error").innerHTML="*密碼不能為空";
return false; //返回false
}else{
document.getElementById("pwd_error").innerHTML="";
return true;
}
}
function jj () {
var userisright = checkuser(document.getElementById("user").value);
var pwdisright = checkpwd(document.getElementById("psw11").value);
if(userisright==true&&pwdisright==true){
return true;
}else{
alert("輸入有錯,登錄失??!");
return false;
}
}
</script>
</head>
<body>
<form action="#" method="post" onsubmit="return jj()">
賬號:
<!--這是一個文本輸入框-->
<input type="text" name="user" id="user" value="" onblur="checkuser(this.value);" />
<span id="user_error" style="color: red;"></span><br/>
密碼:
<!--這是一個密碼輸入框-->
<input type="password" name="psw11" id="psw11" value=""onblur="checkpwd(this.value)"/>
<span id="pwd_error" style="color: red;"></span><br/>
<!--這是一個提交按鈕-->
<input type="submit" value="登錄"/>
</form>
</body>
</html>