注冊高高亮用戶.jpg
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.wrong {
border: 2px solid red;
}
.right {
border: 2px solid #91B81D;
}
</style>
</head>
<body>
賬號:<input type="text" onblur="fn(this)"/><br><br>
密碼:<input type="password" onblur="fn(this)"/>
<script>
//需求:失去焦點的時候判斷input按鈕中的值,如果賬號或密碼在6-12個字符之間通過,否則報錯。
//步驟:
//1.獲取事件源
//2.綁定事件
//3.書寫事件驅動程序
//3.書寫事件驅動程序
function fn(aaa){
//html中的input標簽行內調用function的時候,是先通過window調用的function,所以打印this等于打印window
// console.log(this)
//只有傳遞的this才指的是標簽本身。
// console.log(aaa)
// console.log(this.value)
if(aaa.value.length < 6 || aaa.value.length>12){
aaa.className = "wrong";
}else{
aaa.className = "right";
}
}
</script>
</body>
</html>