我在 IE8 和 IE9 上遇到“this.0.files.0”为空或不是对象错误,Chrome 和 Mozila 不会抛出任何错误。
$(function()) {
var fileType = ['txt' , 'csv' ];
$('.input_file').find('input [type = "file" ]').live('change', function (e)) {
$this = $(this)
var ext = $this.val() === " " ? " " : this.value.match(/\.(.+)$/)[1];
if($this.val()) {
$this.parent().find('label').text.($this[0].files[0].name)
}
}
}
我不确定为什么上面的代码会抛出 javascript 错误 'this.0.files.0' is null or not an object
最佳答案
IE < 10 不支持 html5 文件 API,即不支持 HTMLInputElement.FileList
,您必须解析 HTMLInputElement.value
才能获取文件名。
关于IE8 和 IE9 上的 Javascript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16255636/