GWT: Trouble getting value from a text box

前端 未结 2 882
情书的邮戳
情书的邮戳 2021-01-19 06:17

I\'m using GWT 2.4. I\'m trying to submit an AJAX request with the only input being the value of a text field on the page. Here is how I attach the handler to the page\'s

2条回答
  •  时光取名叫无心
    2021-01-19 06:51

    Try using DOM.getPropertyString / DOM.getElementProperty

    Following is the javadoc from GWT source for getAttribute function. It clearly says that the support for javascript's "getAttribute" function could be inconsistent for a few browsers and thus Element and subclasses should be used.

    Alternatively you can use DOM.getPropertyString to fetch a value which uses object notation of javascript to get te current value

    /**
    * Retrieves an attribute value by name.  Attribute support can be
    * inconsistent across various browsers.  Consider using the accessors in
    * {@link Element} and its specific subclasses to retrieve attributes and
    * properties.
    * 
    * @param name The name of the attribute to retrieve
    * @return The Attr value as a string, or the empty string if that attribute
    *         does not have a specified or default value
    */
    public final String getAttribute(String name) {
        return DOMImpl.impl.getAttribute(this, name);
    }
    

    I tried using javascript's "getAttribute" function to get value of a text field in IE8 and FF6. IE gave the updated value of the text field while FF did not. Here is the fiddle

    http://jsfiddle.net/GvNu4/

提交回复
热议问题