我代码出了什么问题,为什么实现不了

来源: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回答

三年没洗澡

2019-02-07

    $('input').focus(function(){
        $('span').text('请输入用户名');
    }).blur(function(){
        if($(this).val()==''){
            $(this).css('borderColor','red');
            $('span').text('用户名不能为空');
        }else{
            $(this).css('borderColor','green');
            $('span').text('');
        }
    });

我是这样写的

0

好帮手慕夭夭

2019-02-11

你好同学 , 获取的输入内容是字符串类型 ,应该判断是否为空字符串 , 如下:

http://img.mukewang.com/climg/5c60d8bb0001236f07530359.jpg

祝学习愉快 ,望采纳 .

0

0 学习 · 36712 问题

查看课程