老师请看一下是否正确
来源:4-3 编程练习
慕函数4234673
2020-01-13 18:14:02
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>习题</title>
</head>
<body>
<input type="text" value=""><span></span>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
$(document).ready(function(){
$("input").focus(function(){
if($(this).val()==""){
$(this).css({"borderColor":"blue"})
$("span").text("用户名不能为空")
}else{
$("span").text("")
}
})
$("input").blur(function(){
$("span").text("请输入用户名")
$(this).css({"borderColor":"red"})
})
})
</script>
</body>
</html>
1回答
好帮手慕码
2020-01-13
同学你好,按照效果图可以优化如下:
如果我的回答帮到了你,欢迎采纳,祝学习愉快~
相似问题