Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript验证检查特定高度和宽度输入类型文件_Javascript_File_Validation - Fatal编程技术网

javascript验证检查特定高度和宽度输入类型文件

javascript验证检查特定高度和宽度输入类型文件,javascript,file,validation,Javascript,File,Validation,我在网上发现了这段代码,它只检查文件类型,如何将文件高度和文件宽度以及文件大小添加到jquery函数中 我在网上发现了这段代码,它只检查文件类型,如何将文件高度和文件宽度以及文件大小添加到jquery函数中 (function($) { $.fn.checkFileType = function(options) { var defaults = { allowedExtensions: [], success: funct

我在网上发现了这段代码,它只检查文件类型,如何将文件高度和文件宽度以及文件大小添加到jquery函数中 我在网上发现了这段代码,它只检查文件类型,如何将文件高度和文件宽度以及文件大小添加到jquery函数中

(function($) {
    $.fn.checkFileType = function(options) {
        var defaults = {
            allowedExtensions: [],
            success: function() {},
            error: function() {}
        };
        options = $.extend(defaults, options);

        return this.each(function() {

            $(this).on('change', function() {
                var value = $(this).val(),
                    file = value.toLowerCase(),
                    extension = file.substring(file.lastIndexOf('.') + 1);

                if ($.inArray(extension, options.allowedExtensions) == -1) {
                    options.error();
                    $(this).focus();
                } else {
                    options.success();

                }

            });

        });
    };
})(jQuery);
召唤

$(function() {
    $('#shop_logo').checkFileType({
        allowedExtensions: ['jpg', 'jpeg'],
        success: function() {
            alert('Success');
        },
        error: function() {
            alert('Only jpg images');
        }
    });
});

看看,javascript只能访问页面上的html。而不是文件。也许html中包含了类似的代码。您想从那里提取数据吗?或者您如何访问有问题的文件?上载文件时,基本功能通过文件名工作。检查扩展名是检查文件名的一部分,这很简单。检查图像尺寸要复杂得多。您是否准备好应对这种复杂性?对于文件大小,您是否需要支持Internet Explorer 8或9或Opera mini?请参阅上的支持概述