用jquery验证

时间:2015-07-29 15:01:09

标签: javascript jquery

我有这样的js脚本,它验证了我的表格

    $.validator.addMethod("uploadFile", function(value, element){
        var size = element.files.size;
        alert(size);
        if(size <= 52428800)
            return true;
    });


    $(selector).validate({
        submitHandler: function(form) {
            $(form).ajaxSubmit(options);
        },
        focusInvalid: true,
        focusCleanup: true,
        rules: {   
            file: {
                required: false,
                uploadFile: true
            }
        },
        messages: {
            uploadFile: {
                required: "Maximum upload size 50MB. Please try again"
            }

        },
        errorPlacement: function(error, element) {
            var er = element.attr("name");
            element.addClass('error');
        }
    });

我如何打印消息&#34;最大上传大小50MB。我在互联网上阅读,但我无法找到答案。请再试一次&#34;在跨度?

2 个答案:

答案 0 :(得分:0)

您可以使用jQuery访问DOM元素的内容。

$('#YourSpanId').html("Maximum upload size 50MB. Please try again");

答案 1 :(得分:0)

$.validator.addMethod("uploadFile", function(value, element){
    var size = element.files.size;
    alert(size);
    if(size <= 52428800)
        return true;
});


$(selector).validate({
    submitHandler: function(form) {
        $(form).ajaxSubmit(options);
    },
    focusInvalid: true,
    focusCleanup: true,
    rules: {   
        file: {
            required: false,
            uploadFile: true
        }
    },
    messages: {
        uploadFile: {
            required: "Maximum upload size 50MB. Please try again"
            minlength:"Maximum upload size 50MB. Please try again"
        }

    },
    errorPlacement: function(error, element) {
        var er = element.attr("name");
        element.addClass('error');
    }
});