日期:2014-05-16  浏览次数:20433 次

WScript.Shell模拟键盘输入中文的问题
<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)
var   WshShell   =   new   ActiveXObject( "Wscript.Shell ");
form1.fileName1.focus()
for(i=1;i <=len;i++){
var   srcValue=i+ "测试.jpg ";
window.clipboardData.clearData( "text ");
window.clipboardData.setData( "text ",srcValue);
WshShell.sendkeys( "^(v) ");
WshShell.SendKeys( "{TAB} ")
WshShell.SendKeys( "{TAB} ")
}

}
</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>

为什么onTest(1)的时候可以正常的输出中文,当大于1的时候,只是输出最后的一个,例如,当onTest(2)时,fileName1,fileName2中应该分别输出的是:1测试.jpg,2测试.jpg,可是实际2个输出的内容是一致的,都是2测试.jpg

------解决方案--------------------
<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>

昨天也有个人问这个问题,这是斑竹给的答案,你看看吧
------解决方案-----