麻烦老师检查谢谢

来源:4-3 编程练习

慕无忌5206817

2019-12-07 06:13:18

<!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(){
           if($(this).val() ==''){
              $('span').html('请输入用户名');
              $(this).css({'border':'1px solid blue'});
           }else{
               $('span').html('');
               $(this).css({'border':'1px solid green'});
           }          
       });
       $('input').blur(function(){
           if($(this).val() ==''){
               $('span').html('用户名不能为空');
               $(this).css({'border':'1px solid red'});
           }else{
               $('span').html('');
               $(this).css({'border':'1px solid green'});
       };
     })
   })
    </script>
</body>
</html>


写回答

1回答

好帮手慕慕子

2019-12-07

同学你好,代码是正确的,继续加油, 祝学习愉快~

0

0 学习 · 14456 问题

查看课程