开发者

Updating an existing HTML link using GWT?

开发者 https://www.devze.com 2023-02-12 12:02 出处:网络
HTML file: <a id=\"search\">Search</a> GWT Module: Anchor searchLink = new Anchor(\"Search\", Window.Location.createUrlBuild开发者_运维百科er().setPath(\"search.html\").buildString());

HTML file:

<a id="search">Search</a>

GWT Module:

Anchor searchLink = new Anchor("Search", Window.Location.createUrlBuild开发者_运维百科er().setPath("search.html").buildString());
RootPanel.get("search").add(searchLink);

Results in:

<a id="search">Search
  <a class="gwt-Anchor" href="http://127.0.0.1:8888/search.html?gwt.codesvr=127.0.0.1:9997">Search</a>
</a>

Is there a way for me to edit the existing anchor (replacing its body) instead of inserting inside it?


Use Document#getElementById() to get the existing anchor Element instead of RootPanel#get():

Anchor searchLink = Anchor.wrap(Document.get().getElementById("search"));
searchLink.setHref(Window.Location.createUrlBuilder().
  setPath("search.html").buildString());


The correct use of GWT Document class is:

Document.get().getElementById("search")
0

精彩评论

暂无评论...
验证码 换一张
取 消