如何使用忽略的 href 创建 GWT 锚点?
假设我有这样的 HTML 锚点:
<a id="myid" href="something?a=b">Link</a>
我想将其包装在 GWT 锚点中,该锚点具有一个单击处理程序,该处理程序将用户发送到其他位置并忽略 href 值。
在常规的 javascript 中,您似乎可以通过执行以下操作来完成此操作:
<a id="myid" href="something?a=b" onclick="goSomewhereElse(); return false;">Link</a>
但在 GWT 中,似乎没有办法做到这一点...我错过了什么吗?
谢谢!
Let's say I have HTML anchor like so:
<a id="myid" href="something?a=b">Link</a>
and I want to wrap this in a GWT Anchor that has a click handler that sends the user somewhere else and ignores the href value.
in regular javascript it seems like you can accomplish this by doing:
<a id="myid" href="something?a=b" onclick="goSomewhereElse(); return false;">Link</a>
But in GWT there doesn't appear to be a way to do it ... am i missing something?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以只使用 g:Anchor 标签而不是 a 吗?
然后在文件的实现中,您可以有类似的东西...
这将消除根本不需要存在 href 的需要。另外,如果您需要存在 href,因为您有 clickEvent,您可以将 event.preventDefault() 添加到 UiHandler。 (如 UiHandler 中的第二行所示)
也许我完全错过了你想要的东西,但我希望这会有所帮助! :)
Can you just use the g:Anchor tag instead of a?
And then in your implementation of the file you could have something like...
This would eliminate the need to have the href present at all. Also, if you need to have the href present, since you have the clickEvent you could add event.preventDefault() to the UiHandler. (as seen on the second line in the UiHandler)
Maybe I completely missed what you were going for, but I hope this helps a little! :)
使用
锚定
并向其添加一个ClickHandler
。Use
Anchor
and add aClickHandler
to it.创建一个
Anchor
作为new Anchor(textToDisplay)
并向其添加一个ClickHandler
。Create an
Anchor
asnew Anchor(textToDisplay)
and add aClickHandler
to it.将其更改为:
Change it to: