我是jQuery的新手,我需要你帮助我已经阻止了。我需要在上传之前检查每个图像大小。
$(document).ready(function() {
$('#imgfile').each(function() {
$(this).change(function(){
var file_size = $(this)[0].files[0].size;
var imgkbytes = Math.round(parseInt(file_size)/1024);
if(file_size>256001) {
$("#uplod").html("<p><span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span>File size is too large "+imgkbytes+"kb.</p>");
$("#uplod").dialog("open");
$(this).val(null);
}
});
});
$("#uplod").dialog({
modal: true,
autoOpen: false,
width: 400,
buttons: [
{
text: "Ok",
click: function() {
$( this ).dialog( "close" );
}
}
]
});
});
&#13;
<tbody>
<tr>
<td><input type="file" accept="image/*" name="imgfile[]" id="imgfile" class="imgp"></td>
</tr>
<tr>
<td><input type="file" accept="image/*" name="imgfile[]" id="imgfile" class="imgp"></td>
</tr>
<tr>
<td><input type="file" accept="image/*" name="imgfile[]" id="imgfile" class="imgp"></td>
</tr>
<tr>
<td><input type="file" accept="image/*" name="imgfile[]" id="imgfile" class="imgp"></td>
</tr>
</tbody>
<div id="uplod" title="Error in Upload"></div>
&#13;