input框失去焦点时,如果input的value为空,边框等样式改变
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.focus {
border: 1px solid #f00;
background: #fcc;
}
</style>
</head>
<body>
<input id="username" type="text" value="11" />
<input id="pass" type="text" value="11" />
<input id="Text2" type="password" value="11" />
<script src="/jquery.js"></script>
<script>
$('input').blur(function () {
console.log(1);
if(this.value == '') {
console.log(2);
// console.log($(this));
$(this).addClass("focus")
// return false
}else {
$(this).removeClass("focus")
}
})
</script>
</body>
</html>