jquery简单的表单验证密码

<tbody>
    <tr>
        <td style="width:25%">修改密码:</td>
        <td><input type="password" class="input" name="password" value="" id="password"></td>
    </tr>
    <tr>
        <td style="width:25%">确认密码:</td>
        <td><input type="password" class="input" name="password1" value="" id="password1"></td>
    </tr>
</tbody>
<script>
    $(function(){
        $('#button').click(function(){
            var password=$('#password').val();
            var password1=$('#password1').val();
            if(password ==''){
                var flage='<font class="del" color="red">密码不能为空</font>';
                $('.del').remove();
                $('#password').parent().append(flage);
            }else if(password.length<6){
                var flage='<font class="del" color="red">密码长度不小于6位</font>';
                    $('.del').remove();
                    $('#password').parent().append(flage);
            }else{
                if(password1==password){
                    $('form').submit();
                }else{
                    var flage='<font class="del" color="red">两次密码不一致</font>';
                    $('.del').remove();
                    $('#password1').parent().append(flage);
                }
            }
        });
    })
</script>

 

posted @ 2018-02-06 15:26  za_szybko  阅读(323)  评论(0编辑  收藏  举报