<html>
<head>    
<title></title>
<script>
function onTest(len){
form1.fileName1.focus()
for(i=1;i<=len;i++){

var srcValue=i+".jpg";
var WshShell = new ActiveXObject("Wscript.Shell");
//try{
//var obj = eval("document.form1.fileName"+i);
//obj.focus();
WshShell.SendKeys(srcValue);
WshShell.SendKeys("{TAB}")
WshShell.SendKeys("{TAB}")
/*}catch(e){
alert(e);
} */
WshShell.Quit; 
}

}
</script>
</head>
<body>
<table>
  <form name="form1" method="post" action="" enctype="multipart/form-data">
  <tr>
    <td>
<input name="fileName1" type="file"/>
<input name="fileName2" type="file"/>
<input name="fileName3" type="file"/>
<input name="fileName4" type="file"/>
<input name="fileName5" type="file"/>
<input type="button" onClick="onTest(5);" value="ok">
</td>
</tr>
</form>
</table>
</body>
</html>

解决方案 »

  1.   

    谢谢 hbhbhbhbhb1021(天外水火(我要多努力)) 果然有高人再请教一下 当我连续点ok按钮的时候  file里面的值是累加的  能不能在之前先清空一下(不是刷新那种)  ^_^
      

  2.   

    <html>
    <head>    
    <title></title>
    <script>
    function clearTest(len)
    {
    for(i=1;i<=len;i++){
    var obj = eval("document.form1.fileName"+i);
    obj.select();
    document.execCommand("delete")
    }
    }
    function onTest(len){
    clearTest(len)
    form1.fileName1.focus()
    for(i=1;i<=len;i++){

    var srcValue=i+".jpg";
    var WshShell = new ActiveXObject("Wscript.Shell");
    //try{

    //obj.focus();
    WshShell.SendKeys(srcValue);
    WshShell.SendKeys("{TAB}")
    WshShell.SendKeys("{TAB}")
    /*}catch(e){
    alert(e);
    } */
    WshShell.Quit; 
    }

    }
    </script>
    </head>
    <body>
    <table>
      <form name="form1" method="post" action="" enctype="multipart/form-data">
      <tr>
        <td>
    <input name="fileName1" type="file"/>
    <input name="fileName2" type="file"/>
    <input name="fileName3" type="file"/>
    <input name="fileName4" type="file"/>
    <input name="fileName5" type="file"/>
    <input type="button" onClick="onTest(5);" value="ok">
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html>
      

  3.   

    大师啊........没得说,四星真不是白当的啊 
    刚才还忘问了一个问题 : 如果1.jpg  改成是中文文件名 显示不出来 
    这个怎么解决呢?
      

  4.   

    SendKeys只能输入字母、数字或符号键,不能直接输入中文文字,所以要想输入中文消息时必须将文字内容先转换为字根编码(字母键及数字键),也就是说先要切换输入法,如果是做聊天机器人需要设置一个快捷键,这样就可以直接切换到那个输入法。send一个组合键,例如WshShell.SendKeys("+^");
    不过这个Wscript.Shell用的时候一定要小心,安全级别要多注意些,因为客户要么安全级别设的很低,要么把你的内容加到“可信任站点”中了,所以一旦中木马什么的,后果有可能很严重