因为sendkeys是把按键的顺序存起来,然后当JS运行完了以后一次性执行,所以你的CTRL+V复制的就是内存中最后一次复制的值

解决方案 »

  1.   

    <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>昨天也有个人问这个问题,这是斑竹给的答案,你看看吧
      

  2.   

    对不起啊,看错了刚刚,去掉“测试”确实也是不可以的,你刚刚给我的这个答案在文本框里输出的是: 1\.jpg 2\.jpg 为什么会有“\”这个字符??
      

  3.   

    这个东西感觉写WEB程序不是好东西,写CMD程序到是挺好用的,因为里面WScript对象不能用。
    如果用的话只有这样了
    <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()
    show(1,len)
    }
    function show(i,len){
    var srcValue=i+"测试.jpg";
    window.clipboardData.clearData("text");
    window.clipboardData.setData("text",srcValue);
    var WshShell = new ActiveXObject("Wscript.Shell");
    WshShell.sendkeys("^(v)");
    WshShell.SendKeys("{TAB}")
    WshShell.SendKeys("{TAB}")
    WshShell.Quit;
    if(i>len){
    return
    }
    i++
    setTimeout("show('"+i+"','"+len+"')",100)
    }
    </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 type="button" onClick="onTest(4);" value="ok">
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html>