`
yonglin4605
  • 浏览: 183557 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Element

    博客分类:
  • GWT
阅读更多
这里的Element是指com.google.gwt.dom.client.Element
因为GWT里面有不止一个Element类,所以请不要混淆


Element表示的是js里面的element对象,看一下他源代码里的部分方法
  /**
   * 这是我们在js中常用的innerHTML方法,使用了JSNI
   */
  public final native void setInnerHTML(String html) /*-{
     this.innerHTML = html || '';
   }-*/;
  /**
   * 获得该Element里面的html代码,这里并没有直接使用JSNI,因为不同的浏览器实现这个功能的方法不一样,这里的代码在执行的时候,会根据你的浏览器来选择不同的实现类来执行
   */
  public final String getInnerHTML() {
    return DOMImpl.impl.getInnerHTML(this);
  }
  /**
   * 获得这个Element的Tag标记
   */
  public final native String getTagName() /*-{
     return this.tagName;
   }-*/;
  /**
   * Adds a new attribute. If an attribute with that name is already present in
   * the element, its value is changed to be that of the value parameter.
   * 
   * @param name The name of the attribute to create or alter
   * @param value Value to set in string form
     设置这个Element上的属性和值,如果该属性还没有,则创建,如果已经存在,则替换
   */
  public final native void setAttribute(String name, String value) /*-{
     this.setAttribute(name, value);
   }-*/;
  /**
   * The class attribute of the element. This attribute has been renamed due to
   * conflicts with the "class" keyword exposed by many languages.
   * 
   * 设置Element上的class属性
   */
  public final native void setClassName(String className) /*-{
     this.className = className;
   }-*/;
  /**
   * The element's identifier.
   * 
   * 设置Element上的id属性
   */
  public final native void setId(String id) /*-{
     this.id = id;
   }-*/;


Element有很多子类,基本上都是按照tag来分类的
如AnchorElement对应的是<a></a>
AreaElement对应的是<area></area>
FormElement对应的是<form></form>
等等。。。。
对应不同的tag类型,会提供不同的方法来设置特有的属性
分享到:
评论
1 楼 woodytf 2011-02-17  
您好,我想请问下我用(AnchorElement) Document.get().getElementById("***")获得一个用HTML创建的一个超链接a标签,我怎样给这个AnchorElement对象添加一个单击事件呢?

相关推荐

Global site tag (gtag.js) - Google Analytics