我代码出了什么问题,为什么实现不了
来源:4-3 编程练习
走去偷柿子呀
2019-02-07 21:20:28
<!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>
$(document).ready(function(){
$("input").focus(function(){
$("span").html("请输入用户名")
})
$("input").blur(function(){
if($(this).value==null){
$("span").text("用户名不能为空");
$(this).css({"borderColor":"red"})
}
else if($(this).val()!=null){
$("span").text("");
$(this).css({"borderColor":"green"})
}
})
})
//此处写代码
</script>
</body>
</html>
2回答
$('input').focus(function(){ $('span').text('请输入用户名'); }).blur(function(){ if($(this).val()==''){ $(this).css('borderColor','red'); $('span').text('用户名不能为空'); }else{ $(this).css('borderColor','green'); $('span').text(''); } });
我是这样写的
好帮手慕夭夭
2019-02-11
你好同学 , 获取的输入内容是字符串类型 ,应该判断是否为空字符串 , 如下:
祝学习愉快 ,望采纳 .
相似问题