JavaScript DOM操作案例判断密码长度
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="password" value="" id="pw"/> <script src="common.js"></script> <script> //获取文本框 my$("pw").onblur = function () { //判断密码长度 if (this.value.length >= 6 && this.value.length <= 10) { this.style.backgroundColor = "red"; } else { this.style.backgroundColor = "green"; } }; </script> </body> </html>