好日子,的Javascript:模拟<INPUT TYPE =“文件”>
我想模拟浏览文件元素上的点击,但我不能使它工作的点击。
我发现这一点: http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/
,并试图和它的“按钮”工程和“提交”类型:
<input type="checkbox" onClick="document.getElementById('theSubmitButton').click();">Check the box to simulate a button click
<input type="submit" name="theSubmitButton" id="theSubmitButton" value="Button" onClick="alert('The button was clicked.');">
但是当我试图将其更改为“文件”类型:
<input type="checkbox" onClick="document.getElementById('theSubmitButton').click();">Check the box to simulate a button click
<input type="file" name="theSubmitButton" id="theSubmitButton" value="Button" onClick="alert('The button was clicked.');">
它不适用于Firefox和IE8。但文件浏览器窗口出现在谷歌浏览器中。
这种方法有问题吗?我怎么能使它在FF和IE8中工作?
非常感谢!
只是一个除了这样的回答:如果你需要通过随机的时间来打开文件对话框 - 您可以使用基于flash的上传。 – bezmax 2010-12-15 15:41:25
我明白了,非常感谢你回复我的问题。 :) – srcastro 2010-12-15 16:10:12
“安全”,“功能” – user445786 2013-12-15 16:29:09