失去焦点时未成功
来源:4-3 编程练习
CloveZ
2019-05-06 20:36:51
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>习题</title>
</head>
<body>
<input type="text" value=""><span></span>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
$("input").focus(function(){
$("span").text("请输入用户名");
$(this).css({"boderColor":""})
});
$("input").blur(function(){
if($(this).val==""){
$("span").text("用户名不能为空");
$(this).css({"boderColor":"red"});
}else{
$(this).css({"boderColor":"green"});
}
});
</script>
</body>
</html>
1回答
feelbe
2019-05-06
($(this).val=="")这句中的 val 改成val(),就可以了
相似问题