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")
精彩评论