SOURCE

console 命令行工具 X clear

                    
>
console
$(function () {
    $('span').css("color", "red").css("font-size", "0.7em")
    
    $("input").focus(function () {
        console.log($(this))
        $(this).next('span').text('')
    })
    $("input[name='uname']").blur(function () {
        $(this).next('span').text('用户名不能为空')
    })
    $("input:password").blur(function () {
         $("input:password").next('span').text('密码不能为空')
    })


    $('#btn').click(function () {
        let uname = $("input[name='uname']").val()
        let pwd = $('input:password').val()
        if (uname === null || uname.length === 0) {
            console.log('uname null')
            $("input[name='uname']").next('span').text('用户名不能为空')
        }
        if (pwd === null || pwd.length === 0) {
            console.log('uname null')
            $("input:password").next('span').text('密码不能为空')
        }
        if (uname === 'admin' || pwd == '123') {
            alert("登陆成工")
        }



    })
})
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<form>
    <div>
        <input name="uname"/><span></span>
    </div>
    <div>
        <input type="password" name="pwd"/><span></span>
    </div>
    <input id="btn" type="button" value="登录"/>
</form>