Sha*_*eKm 5 javascript jquery internet-explorer mozilla
我有以下输入文件标记:
<input type="file" id="handlerxhr1" />
Run Code Online (Sandbox Code Playgroud)
在mozilla中,当我运行以下jQuery代码时:
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
alert(input.files[0]);
});
Run Code Online (Sandbox Code Playgroud)
我得到回复:[对象文件](这很好).
但是在IE中我得到'input.files.0 is undefined'
我究竟做错了什么?谢谢.
IE不支持.files [0]属性,而FF则支持.files [0]属性.有关详细信息,请参见http://www.w3.org/TR/FileAPI/
这看起来已经足够好了...
$(function() {
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
alert(input);
});
});
Run Code Online (Sandbox Code Playgroud)
不确定你是否在追求这样的东西:
$(function() {
var input = $('#handlerxhr1')[0];
$('#upload').click(function() {
var x = $('input[type=file]:eq(0)');
alert(x);
});
});
Run Code Online (Sandbox Code Playgroud)