解决方法
你可以在扩展上验证……
$('form').submit(function(event) { var file = $('input[type=file]').val(); if ( ! file) { alert('The file is required.'); event.preventDefault(); return; } if (file.match(/\.(?:csv|xl)$/)) { alert('CSV or Excel files only!'); event.preventDefault(); } });
…或者你可以验证mime类型.
$('form').submit(function(event) { var file = $('input[type=file]').prop('files')[0]; if ( ! file) { alert('The file is required.'); event.preventDefault(); return; } var mime = file.type; if (mime != 'text/csv' || mime != 'application/vnd.ms-excel') { alert('CSV or Excel files only!'); event.preventDefault(); } });