gwt - 如何在 FileUpload 小部件上触发 clickEvent?
我正在尝试创建一个简单的按钮,当单击它时,我想触发 FormPanel 内的隐藏 FileUpload 小部件。到目前为止我所做的是两件事:
- 我创建了一个本机 javascript 单击 FileUpload 的函数 简单时小部件的元素 单击按钮。这有效 在 Firefox 中很好,但不起作用 在 Chrome 中。
- 另外,我还创建了 这:NativeEvent nevent = Document.get().createFocusEvent();//我也尝试过createclickEvent()。
DomEvent.fireNativeEvent(nevent, fileUploadWidget);这不 根本不工作。
有人可以帮我吗???我已经搜索了很多,但我发现没有任何作用。
I' m trying to create a simple Button and when it's clicked I want to trigger a hidden FileUpload widget which is inside a FormPanel. What I have done until now is two things:
- I have created a native javascript
function that clicks the FileUpload
widget's element when simple
button is clicked. This works
fine in Firefox but it doesn't work
in Chrome. - Also, I have created
this: NativeEvent nevent =
Document.get().createFocusEvent();//I have tried and createclickEvent() too.
DomEvent.fireNativeEvent(nevent, fileUploadWidget); This doesn't
work at all.
Can anyone help me please??? I have searched a lot but I find nothing working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是您正在寻找的。
为了使其在基于 WebKit 的浏览器(Chrome、Safari)中工作,FileUpload 必须“移出视图”但不能隐藏(如
setVisible(false)
中所示,它设置 CSSdisplay
属性改为none
),即类似(在 CSS 中):position:absolute;顶部:-1000px;左:-1000px;
is what you're looking for.
For it to work in WebKit-based browsers (Chrome, Safari), the FileUpload has to be "moved out of view" but not hidden (as in
setVisible(false)
, which sets the CSSdisplay
property tonone
), i.e. something like (in CSS):position:absolute; top: -1000px; left: -1000px;
我相信 Thomas Broyer 的答案现在已经过时了。我刚刚成功使用
myFileUpload.click()
,没有任何问题。我还在
FileUpload
字段上使用了setVisible(false)
,并且它在 Chrome 中有效。尚未在 Safari 中进行测试,但看来这些问题现在已经得到解决。I believe Thomas Broyer's answer is out of date now. I have just successfully used
myFileUpload.click()
with no problems.I also used
setVisible(false)
on the theFileUpload
field and it works in Chrome. Haven't tested in Safari but it would seem those issues have been resolved now.您还可以像这样使用 JSNI:
然后调用
You can also use JSNI like this:
Then call