2009-12-29 91 views
0

我正在使用Multifile插件來選擇多個文件。我正在嘗試爲每個瀏覽器選擇獲得最終文件數 。任何幫助表示讚賞。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> 

回答

2

你不需要addUploadFile功能的示例代碼,多文件會照顧它。保留一個計數器,只是掛到onFileAppendonFileRemove,像這樣:

HTML:

<input type="file" id="upload" name="upload" /> 

JS:

var count = 0; 
$(document).ready (function() { 
    $('#upload').MultiFile ({ 
     onFileAppend: function() { ++count; }, 
     onFileRemove: function() { --count; } 
    }); 
});