【问题标题】:GWT : create DOM element using JSNIGWT:使用 JSNI 创建 DOM 元素
【发布时间】:2013-09-16 06:46:20
【问题描述】:

我对在 GWT 中使用 JSNI 比较陌生,只是想知道是否可以使用 JSNI 创建 DOM 元素? 我尝试使用以下内容:

private class myImageElement extends ImageElement {

    private boolean inUse = false;

    protected myImageElement() {}

    public final native void setIfinUse(boolean check) /*-{this.inUse=check}-*/ ;

    public final native boolean checkIfinUse() /*-{return this.inUse}-*/ ;
}

现在创建 myImageElement 对象的代码是:

private native myImageElement get() /*-{ what should be here } -*/

由于我没有找到使用 JSNI 创建它的方法,任何人都可以告诉我我是否正确地执行它吗?

【问题讨论】:

    标签: gwt jsni


    【解决方案1】:

    您可以使用 GWT 的 Document 类创建它,并将 Element 转换为新的 Element 类。

     myImageElement element =(myImageElement) Document.get().createImageElement();
    

    但是,在 GWT 中,所有 *Elementclasses 都是进行强制转换的方法:

     public static myImageElement as(Element elem) {
       assert elem.getTagName().equalsIgnoreCase("img");
       return (myImageElement) elem;
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 2012-04-13
      • 2012-03-06
      • 2018-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多