因为sendkeys是把按键的顺序存起来,然后当JS运行完了以后一次性执行,所以你的CTRL+V复制的就是内存中最后一次复制的值
解决方案 »
- js代码,下拉列表提交,选项中如果有空格,为什么会自动去掉空格后面的信息?
- JS在操作cookie时,cookie的过期日期存在Bug吗?
- 纠结人的问题,document.createElement("div")后却不能获取
- 请问这个功能怎么实现?谢谢!
- document.cookie不支持中文?
- chrome如何使用input type=“file” 获得真实路径 不是fakePath 求解!
- 新开窗口控制父窗口转向的问题,内详
- 请大家帮忙修改一个正则表达式
- 有关菜单特效(300分,急,可令开贴结分)
- extjs 3 border 布局.west加两个树怎么实现
- JS替换字符的简单问题
- 请教javascript正则表达式
<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>昨天也有个人问这个问题,这是斑竹给的答案,你看看吧
如果用的话只有这样了
<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>