jQuery change method on input type=“file”

后端 未结 3 696
北荒
北荒 2020-12-02 11:56

I\'m trying to embrace jQuery 100% with it\'s simple and elegant API but I\'ve run into an inconsistency between the API and straight-up HTML that I can\'t quite figure out.

3条回答
  •  情话喂你
    2020-12-02 12:21

    I could not get IE8+ to work by adding a jQuery event handler to the file input type. I had to go old-school and add the the onchange="" attribute to the input tag:

    
    
    function getFileName(elm) {
       var fn = $(elm).val();
       ....
    }
    

    EDIT:

    function getFileName(elm) {
       var fn = $(elm).val();
       var filename = fn.match(/[^\\/]*$/)[0]; // remove C:\fakename
       alert(filename);
    }
    

提交回复
热议问题