我试图通过检查使用JQuery给出的文件名格式的文件名..jQuery的检查文件类型输入上传文件名
这是我的代码:
<input class="" name="myfile" id="myfile" type="file" multiple="false" data-value="">
我的jQuery脚本:
function checkFileName(filename, file_id){
var must_filename;
must_filename = jQuery(file_id).attr('data-value').split('.').slice(0, 2).join('.');
jQuery('.file_err_det').remove();
alert(must_filename + ' != ' + filename);
// filename value is always null?
if(must_filename != filename){
alert('Filename is not valid! Please follow the format and upload it again');
jQuery(file_id).val('');
}
}
jQuery('#myfile').blur(function() {
var this_filename = jQuery(this).val().split('.').slice(0, 2).join('.');
checkFileName(this_filename, '#myfile');
alert(this_filename); // this returns null? I dont know why..
});
但似乎值this_filename
为空。我正在使用blur
,有什么我可以用来检查jQuery('#myfile').val()
?