文件域是不能直接赋值的,但可以通过sendkey来给文件域输入文件名,相当于模拟键盘输入。
下面的程序的作用是读取某个目录下所有文件,把这些文件名填写到9个文件域中。
<body>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#000000">
<tr>
<td height="24" bgcolor="#FFFFFF">选择任意一个要上传的文件:
<input name="filestr" type="file" id="filestr" size="40" onchange="getfile(this)" /></td>
</tr>
<form name="frm1" enctype="multipart/form-data" method="post">
<tr>
<td height="24" bgcolor="#FFFFFF">需要上传的文件如下:</td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">1.文件1
<input name="file1" type="file" id="file1" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">2.文件2
<input name="file2" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">3.文件3
<input name="file3" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">4.文件4
<input name="file4" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">5.文件5
<input name="file5" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">6.文件6
<input name="file6" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">7.文件7
<input name="file7" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">8.文件8
<input name="file8" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">9.文件9
<input name="file9" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF"><input name="" type="text" style="width:0" /><input type="button" name="Submit" value="全部上传" onclick="doit()"/></td>
</tr>
</form>
</table>
<script>
var i;
i=1;
function getfile(a){
var b;
var n;
b=a.value;
c="\\"
n=b.lastIndexOf(c);
subfile=(b.substring(0,n));
//subfile=subfile.replace(/\\/g,"\\");
//alert(subfile)
ShowFolderList(subfile)
/*
var WshShell1 = new ActiveXObject("WScript.Shell");
document.frm1.reset();
document.frm1.file1.focus();
WshShell1.SendKeys(subfile+"\\1.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\2.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\3.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\4.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\5.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\6.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\7.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\8.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\9.txt");
*/
}
function doit(){
document.frm1.submit();
}
function ShowFolderList(folderspec){
var i;
var fso, f, fc, s;
i=1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.Files);
var WshShell1 = new ActiveXObject("WScript.Shell");
document.frm1.reset();
document.frm1.file1.focus();
for (; !fc.atEnd() && i<=9; fc.moveNext()){
//alert(fc.item());
s=fc.item()+"";
//s=s.replace(/\\/g,"\\");
WshShell1.SendKeys(s.replace(/\\/g,"\\"));
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
i++;
}
}
</script>
</body>
了解更多请访问:http://www.ndfweb.cn/news-291.html
下面的程序的作用是读取某个目录下所有文件,把这些文件名填写到9个文件域中。
<body>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#000000">
<tr>
<td height="24" bgcolor="#FFFFFF">选择任意一个要上传的文件:
<input name="filestr" type="file" id="filestr" size="40" onchange="getfile(this)" /></td>
</tr>
<form name="frm1" enctype="multipart/form-data" method="post">
<tr>
<td height="24" bgcolor="#FFFFFF">需要上传的文件如下:</td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">1.文件1
<input name="file1" type="file" id="file1" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">2.文件2
<input name="file2" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">3.文件3
<input name="file3" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">4.文件4
<input name="file4" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">5.文件5
<input name="file5" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">6.文件6
<input name="file6" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">7.文件7
<input name="file7" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">8.文件8
<input name="file8" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF">9.文件9
<input name="file9" type="file" size="40" /></td>
</tr>
<tr>
<td height="24" bgcolor="#FFFFFF"><input name="" type="text" style="width:0" /><input type="button" name="Submit" value="全部上传" onclick="doit()"/></td>
</tr>
</form>
</table>
<script>
var i;
i=1;
function getfile(a){
var b;
var n;
b=a.value;
c="\\"
n=b.lastIndexOf(c);
subfile=(b.substring(0,n));
//subfile=subfile.replace(/\\/g,"\\");
//alert(subfile)
ShowFolderList(subfile)
/*
var WshShell1 = new ActiveXObject("WScript.Shell");
document.frm1.reset();
document.frm1.file1.focus();
WshShell1.SendKeys(subfile+"\\1.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\2.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\3.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\4.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\5.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\6.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\7.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\8.txt");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys(subfile+"\\9.txt");
*/
}
function doit(){
document.frm1.submit();
}
function ShowFolderList(folderspec){
var i;
var fso, f, fc, s;
i=1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.Files);
var WshShell1 = new ActiveXObject("WScript.Shell");
document.frm1.reset();
document.frm1.file1.focus();
for (; !fc.atEnd() && i<=9; fc.moveNext()){
//alert(fc.item());
s=fc.item()+"";
//s=s.replace(/\\/g,"\\");
WshShell1.SendKeys(s.replace(/\\/g,"\\"));
WshShell1.SendKeys("{TAB}");
WshShell1.SendKeys("{TAB}");
i++;
}
}
</script>
</body>