Javascript file.type is not working on IE 11

2019-05-06 17:46发布

I am trying to check the file type in javascript and my code is:

file.type.match('application/pdf')

function checkPropertyFileValidity(){
        var property_file_input = document.getElementById('property_file');
                if(!jQuery('.property_doc_div .property_doc_icon').hasClass("hidden")) {
            jQuery('.property_doc_div .property_doc_icon').addClass("hidden");
        }
        if (property_file_input.files && property_file_input.files[0]) {
            var property_file = property_file_input.files[0];
            jQuery('.property_doc_div .remove_selected_file').removeClass('hidden');
            if(property_file.type.match('application/pdf') && property_file.size <= 5242880) {
                console.log(property_file.type.match('application/pdf'));
                                jQuery('.help-inline.property_file_error').html('');
                jQuery('.property_doc_div #property_doc_icon').attr("title",property_file.name);
                jQuery('.property_doc_div .property_doc_icon').removeClass("hidden");
                return true;
            } else if(!property_file.type.match('application/pdf')) {
                                console.log(property_file.type.match('application/pdf'));
                jQuery('.help-inline.property_file_error').html('You can select only pdf files');
                return false;
            } else if(property_file.size > 5242880) {
                jQuery('.help-inline.property_file_error').html('File can not be greater than 5 MB');
                return false;
            }
        }
        return true;
    }

Following is the version of my IE 11 enter image description here

and doing file.type gives empty string. Now this thing works good for chrome , Firefox and on IE 10 but not on IE 11. Kindly help me !!!

0条回答
登录 后发表回答