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>
个人小站,欢迎访问!http://klvr.xyz
原文地址:https://www.cnblogs.com/xxks/p/15562566.html