老师 颜色怎么没有变化啊?
来源:4-3 编程练习
一只会跳桑巴的猪
2019-02-25 21:17:58
<!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>
$(function(){
$('input').focus(function(){
$('span').text('请输入用户名');
$('span').css('border-color','blue');
});
$('input').blur(function(){
if($('input').val()==""){
$('span').text('用户名不能为空');
$('span').css('border-color','red');
}else{
$('span').css('border-color','green');
$('span').text('');
};
})
})
</script>
</body>
</html>
1回答
同学你好,要改变的是当前input的边框样式,而不是span边框哦,参考下图:
可以试一试哦,如果帮助到了你,欢迎采纳。
祝学习愉快!
相似问题