您好,
我试图模拟点击浏览文件元素,但是我无法使其工作。
我找到了这个链接:http://www.randomsnippets.com/2008/03/05/simulate-a-button-click-via-javascript/
并尝试使用它来模拟'button'和'submit'类型的点击,成功了:
<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中无法正常工作。但是在Google Chrome中,文件浏览器窗口可以显示出来。
这种方法存在问题吗?我该如何让它在FF和IE8中正常工作呢?
非常感谢!