Jquery在文件类型输入中检查上传文件名 [英] Jquery checking the upload filename in file type input
问题描述
我的JQuery脚本:< input class =name =myfileid =myfiletype =filemultiple =falsedata-value => $ c $
$ p $函数checkFileName(filename, file_id){
var must_filename;信范范内信息范范亦范端范范亦范秘程预期
jQuery('。file_err_det')。remove();
alert(must_filename +'!='+ filename);
//文件名值始终为空?
if(must_filename!= filename){
alert('文件名无效!请按照格式重新上传');
jQuery(file_id).val('');
$ b 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知道为什么..
});
但是看起来值 this_filename
是null 。我正在使用 blur
,是否有任何可以用来检查 jQuery('#myfile')。val()$ c $
File API可以访问一个FileList,方态方范亦读据说亦读信息亦范范段中信息亦范端亦数信息中信息上范读范范中信息资范信息亦中信息亦读信息预秘上亦亦信息上范读中信息中信息内预辛> var selectedFile = document.getElementById('input')。files [0];
使用jQuery选择器访问一个选定的文件: / p>
var selectedFile = $('#input')。get(0).files [0];
p>
var selectedFile = $('#input')[0] .files [0];
尝试使用变更事件
($ change),function(e){var file = e.target.files [0];}。 console.log(file,file.name);})