django+ajax实现简单校验

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="http://mat1.gtimg.com/libs/jquery/1.12.0/jquery.js"></script>
</head>
<body>
<form action="" method="post">
    {% csrf_token %}
    帐号: <input type="text" name="uname" onblur="f()" id="n" value="{{ a }}"> <span id="s"></span><br>
    密码: <input type="text" name="pwd"  value="{{ b }}"><br>
    <button>登录</button>
    <input type="checkbox" value="1" name="e">记住密码
</form>
<script>
    function f() {
        var n = $('#n').val()
        if (n.length === 0) {
            $('#s').html('字段不能为空')
            $('#s').css('color', 'red')
        } else {
            $('#s').html('')
            $('#s').css('color', 'blue')
        }
    }
</script>
</body>
</html>

 

posted @ 2021-11-16 17:53  史可轩  阅读(44)  评论(0编辑  收藏  举报
3 4