0

I am new relatively new to using JSNI in GWT, just wanted to know whether its possible to create a DOM elelment using JSNI? I have tried to use the following:

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}-*/ ;
}

Now the code to create an object of myImageElement would be:

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

Since I didnt not find anyway to create it using JSNI, can anybody please let me know whether I am doing it correctly or not?

4

1 回答 1

2

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

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

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

 public static myImageElement as(Element elem) {
   assert elem.getTagName().equalsIgnoreCase("img");
   return (myImageElement) elem;
 }
于 2013-09-16T08:35:01.493 回答