边框颜色重叠
来源:4-3 编程练习
郝存杰
2019-03-05 17:16:44
<!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(){
$(this).css('borderColor','Light blue');
$('span').text('请输入用户名')
});
$('input').blur(function(){
if($(this).val()==''){
$(this).css('borderColor','red');
$('span').text('用户名不能为空')
}
else{
$(this).css('borderColor','green');
$('span').text('')
}
});
</script>
</body>
</html>
再次获得焦点时,边框颜色会红蓝重叠
1回答
同学你好,这是因为input标签自带边框样式,所以效果显示的不明显,可以在.css()中,直接更改边框所有的样式,参考下图:
这样效果就明显了哦,自己试一试。
如果帮助到了你,欢迎采纳。
祝学习愉快!
相似问题