我有一个用ajax上传文件的表单,文件选择事件是这样的:
# This JS is translated directly from coffeescript
$("input[name=dump_file]").on('change', function() {
# if not .xls do something like window.alert
# else
var dump_file;
return dump_file = this.files[0];
});
我需要检查dump_file
是否为excel格式(.xls或.xlsx),如何在this.files[0]
事件中检查change
文件类型?
答案 0 :(得分:0)
检查文件对象中包含的文件type
:
if (this.files[0].type == "xls/xlsx") { //not sure if that's the right type, you'll have to log it first
//do stuff
}