jQuery:如何重置此类型=";文件";
我需要防止用户上传大图像到服务器,并希望使用简单的输入类型=“文件”。使用下面的jQuery,当this.files超过1048000时,如何重置“输入文件”jQuery:如何重置此类型=";文件";,jquery,Jquery,我需要防止用户上传大图像到服务器,并希望使用简单的输入类型=“文件”。使用下面的jQuery,当this.files超过1048000时,如何重置“输入文件” $('.image-file').bind('change', function() { if ( this.files[0].size > 1048000 ) { alert('Image size can not more than 1Mb.'); // going to reset the file
$('.image-file').bind('change', function() {
if ( this.files[0].size > 1048000 ) {
alert('Image size can not more than 1Mb.');
// going to reset the file
}
});
<input type="file" name="photo[]" class="image-file">
<input type="file" name="photo[]" class="image-file">
<input type="file" name="photo[]" class="image-file">
$('.image文件').bind('change',function()){
如果(此.files[0].size>1048000){
警报('图像大小不能超过1Mb');
//要重置文件吗
}
});
请尝试以下代码。但要获得文件大小,可以使用服务器端代码,该代码将返回文件大小
$('#form_id').each(function(){
this.reset();
});
<input id="fileInput" type="file" onchange="AlertFilesize();" />
}请尝试以下代码。但要获得文件大小,可以使用服务器端代码,该代码将返回文件大小
$('#form_id').each(function(){
this.reset();
});
<input id="fileInput" type="file" onchange="AlertFilesize();" />
}确保检查服务器端所有用户提交的数据。不能使用javascript测量文件上载大小,必须首先使用服务器端语言在服务器端提交。您使用的服务器端语言是什么?PHP?pythonPerl?什么?jQuery真的有必要吗?使用纯香草JS,您可以非常明智地执行
this.value=null代码>.Yes此值=null;工作!确保检查服务器端所有用户提交的数据。不能使用javascript测量文件上载大小,必须首先使用服务器端语言在服务器端提交。您使用的服务器端语言是什么?PHP?pythonPerl?什么?jQuery真的有必要吗?使用纯香草JS,您可以非常明智地执行this.value=null代码>.Yes此值=null;工作!请看一下链接。这是一个工作演示,请看一下链接。这是一个工作演示