$('INPUT[type="file"]').change(function() {
var ext = this.value.match(/\.(.+)$/)[1];
var control = $("#uploaded_file");
switch (ext) {
case 'doc':
case 'docx':
case 'pdf':
case 'wps':
case 'rtf':
case 'txt':
case 'xps':
$('#uploadButton').attr('disabled', false);
break;
default:
alert('\'' + ext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
$('#uploadButton').attr('disabled', true);
control.replaceWith(control = control.val('').clone(true));
}
});
现在我的问题是,如果用户选择具有“.TXT”文件会抛出异常错误,因为TXT是不一样的TXT,所以我尝试使用strtolower功能。但是当我使用它时,脚本本身不起作用。检查文件类型文件的jQuery
改性用strtolower脚本不起作用:
$('INPUT[type="file"]').change(function() {
var ext = this.value.match(/\.(.+)$/)[1];
var cext = strtolower(ext);
var control = $("#uploaded_file");
switch (cext) {
case 'doc':
case 'docx':
case 'pdf':
case 'wps':
case 'rtf':
case 'txt':
case 'xps':
$('#uploadButton').attr('disabled', false);
break;
default:
alert('\'' + cext + '\' is not an allowed file type.\n\nPlease select the correct file type:\n\n\t.DOC, .DOCX, .PDF, .WPS, .RTF, .TXT, .XPS');
$('#uploadButton').attr('disabled', true);
control.replaceWith(control = control.val('').clone(true));
}
});
在哪里,这是造成它不工作的错误?
'用strtolower()'是一个PHP函数,而不是一个JavaScript函数。你正在寻找'String.toLowerCase()'(例如'var ext =“TXT”; switch(ext.toLowerCase()){...')。 – 2013-04-26 20:00:50