Skip to content

Instantly share code, notes, and snippets.

@fengt
Created November 21, 2017 03:23
Show Gist options
  • Save fengt/ea3dd238f248751c910e82a74ad39f8a to your computer and use it in GitHub Desktop.
Save fengt/ea3dd238f248751c910e82a74ad39f8a to your computer and use it in GitHub Desktop.
Upload file extension verification
$('#upload_btn').on('click', function() {
var uploadFile = $('#upload_categories').val();
if (!uploadFile) {
alertify.log('请先选择文件!', 'error', 0);
return;
}
var fileName = uploadFile.substr(uploadFile.lastIndexOf('\\')+1);
var ary = ['xls', 'xlsx'];
var suffix = uploadFile.split('.').pop().toLowerCase();
if ($.inArray(suffix, ary) == -1) {
alertify.log('文件类型有误,请上传excel文件!', 'error', 0);
return;
}
$('#upload_category_form').submit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment