<input type="text" id="userName"><br>
<input type="text" id="userPassword"><br>
<input type="button" id="btnLogin" value="登录">
.highLight {
background-color: red;
}
var userName = document.getElementById('userName');
var userPassword = document.getElementById('userPassword');
var btnLogin = document.getElementById('btnLogin');
btnLogin.onclick = function () {
if (userName.value.length < 3 || userName.value.length > 6) {
userName.className = 'highLight';
return;
} else {
userName.className = '';
}
if (userPassword.value.length < 6 || userPassword.value.length > 8) {
userPassword.className = 'highLight';
return;
} else {
userPassword.className = '';
}
console.log('执行登录');
}