gwt - 如何在 FileUpload 小部件上触发 clickEvent? [英] gwt - how can i trigger clickEvent on FileUpload widget?

查看:18
本文介绍了gwt - 如何在 FileUpload 小部件上触发 clickEvent?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的按钮,当它被点击时,我想触发一个隐藏在 FormPanel 内的 FileUpload 小部件.到目前为止,我所做的是两件事:

  1. 我创建了一个原生 javascript单击 FileUpload 的函数简单的小部件元素按钮被点击.这有效在 Firefox 中很好,但它不起作用在 Chrome 中.
  2. 另外,我已经创建了这:NativeEvent nevent =Document.get().createFocusEvent();//我也试过createclickEvent().
    DomEvent.fireNativeEvent(nevent, fileUploadWidget);这不工作.

谁能帮帮我???我搜索了很多,但没有找到任何工作.

解决方案

myFileUpload.getElement().cast().click()

就是你要找的.

为了在基于 WebKit 的浏览器(Chrome、Safari)中工作,FileUpload 必须移出视图"但不能隐藏(如在 setVisible(false) 中,它设置CSS display 属性为 none),即类似于(在 CSS 中):position:absolute;顶部:-1000 像素;左:-1000px;

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:

  1. 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.
  2. 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.

解决方案

myFileUpload.getElement().<InputElement>cast().click()

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 CSS display property to none), i.e. something like (in CSS): position:absolute; top: -1000px; left: -1000px;

这篇关于gwt - 如何在 FileUpload 小部件上触发 clickEvent?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆