答案 0 :(得分:5)
如果你想使用jQuery的validate
,你可以通过创建这个方法:
$.validator.addMethod('filesize', function(value, element, param) {
// param = size (en bytes)
// element = element to validate (<input>)
// value = value of the element (file name)
return this.optional(element) || (element.files[0].size <= param)
});
你会用它:
$('#formid').validate({
rules: { inputimage: { required: true, accept: "png|jpe?g|gif", filesize: 1048576 }
messages: { inputimage: "File must be JPG, GIF or PNG, less than 1MB" }
});
答案 1 :(得分:1)