开发者

IE input file attribute is undefined

开发者 https://www.devze.com 2023-02-10 18:14 出处:网络
I have the following input file tag: <input type=\"file\" id=\"handlerxhr1\" /> In mozilla when I run the following jQuery code:

I have the following input file tag:

<input type="file" id="handlerxhr1" />

In mozilla when I run the following jQuery code:

var input = $('#handlerxhr1')[0];
        $(开发者_运维问答'#upload').click(function() {
            alert(input.files[0]);

        });

I get response: [object File] (which is good).

But in IE I get 'input.files.0 is undefined'

What am I doing wrong?


IE doesn't support .files[0] property, whereas FF does. See http://www.w3.org/TR/FileAPI/ for more details


This seems good enough...

$(function() {
    var input = $('#handlerxhr1')[0];         
    $('#upload').click(function() {             
        alert(input);          
    }); 
});

Not sure if your were after something like this though:

$(function() {
    var input = $('#handlerxhr1')[0];         
    $('#upload').click(function() {             
        var x = $('input[type=file]:eq(0)');
        alert(x);
    }); 
});
0

精彩评论

暂无评论...
验证码 换一张
取 消