Javascript值的总和与Parsley一起使用

时间:2016-04-20 14:47:43

标签: javascript parsley.js

我有这个代码,我需要与Parsly.js一起工作 - 如何将这个代码插入到他们的结构中,以便向用户显示正确的消息。以下是组验证示例的链接 parsley group validation

<script>
$(document).ready(function(){
    $("#some-form").validate({

        rules: {
            TextBox1: {
                required: true,
                number: true,
                min: 0,
                max: 100,
            },
            TextBox2 : {
                required: true,
                number: true,
                min: 0,
                max: 100,
            }
            TextBox3 : {
                required: true,
                number: true,
                min: 0,
                max: 100,
            }
            TextBox4 : {
                required: true,
                number: true,
                min: 0,
                max: 100,
            }

        },
        submitHandler: function(form){
            var total = parseInt($("#TextBox1").val()) + parseInt($("#TextBox2").val()) + parseInt($("#TextBox3").val()) + parseInt($("#TextBox4").val());
            if (total != 100) {
                $(".error").html("Your total must sum to 100.")
                return false;
            } else form.submit();
        }

    });
});

</script>

0 个答案:

没有答案