我正在使用Multifile插件来选择多个文件。我想要得到 每个浏览器选择的最终文件计数。任何帮助表示赞赏。
以下是我正在使用的示例代码
<html>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.MultiFile.js"></script>
<script>
var intVal=2;
$(document).ready(function(){
$('#addFileButton').click(function(){addUploadFile();});
});
function addUploadFile() {
intVal++;
$('<div id="addVal'+intVal+'">Please specify a file, or a set of files
(dynamically):<br>'+
'<input type="file" class="multi" name="df'+intVal+'" id="df'+intVal+'"
size="40"/></div>').appendTo('#outerVal');
$('#df'+intVal).MultiFile();
}
</script>
<form action="doUpload" enctype="multipart/form-data" method="post">
<div id="outerVal">
<!--p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p-->
<div id="addVal1">
Please specify a file, or a set of files:<br>
<input type="file" class="multi" name="df1" size="40">
</div>
<div id="addVal2">
Please specify a file, or a set of files:<br>
<input type="file" class="multi" name="df2" size="40">
</div>
</div>
<div>
<input type="submit" value="Send">
<input type="button" class="button" value="Add File" id="addFileButton" />
</div>
</form>
</html>
答案 0 :(得分:2)
您不需要addUploadFile
功能,Multifile会为您处理。要保留一个计数器,只需加入onFileAppend
和onFileRemove
,就像这样:
HTML:
<input type="file" id="upload" name="upload" />
JS:
var count = 0;
$(document).ready (function () {
$('#upload').MultiFile ({
onFileAppend: function () { ++count; },
onFileRemove: function () { --count; }
});
});