GWT g:Anchor 不显示为链接
我刚刚开始学习 UiBinder 方法,并且遇到了 g:Anchor
的愚蠢问题。每当我直接从 Java 代码构造 Anchor
时,它都会显示为“正常链接”,因此它是蓝色的,带有下划线,当我将鼠标指针移到它时,它会从 I-Beam 切换为正常箭头。
当我使用 UiBinder 并像这样定义我的 UI 时:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:Anchor ui:field="anchor" />
</ui:UiBinder>
我得到的结果是蓝色文本,但当我将其移动到此链接时,它既没有下划线,也没有鼠标指针变成正常箭头。我发现的唯一解决方案是
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:Anchor ui:field="anchor" href="javascript:;" />
</ui:UiBinder>
是否有一种“正确”的方法可以实现相同的行为,而无需在各处复制粘贴该 href
属性?
I've just started learning UiBinder approach and having a stupid problem with g:Anchor
. Whenever I construct Anchor
directly from Java code, it's displayed as a "normal link", so it's blue, underlined and when I move mouse pointer to it, it gets switched from I-Beam to normal arrow.
When I use UiBinder and define my UI like this:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:Anchor ui:field="anchor" />
</ui:UiBinder>
The result I get is a blue text, but it's neither underlined nor mouse pointer becomes normal arrow when I move it to this link. The only solution I've found is
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<g:Anchor ui:field="anchor" href="javascript:;" />
</ui:UiBinder>
Is there a "correct" approach to achieve the same behavior without copypasting that href
attribute everywhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 http://code.google.com/p/google-web-toolkit /issues/detail?id=4502
但问题是,如果您没有设置
href
,则不应使用 Anchor。如果您想要看起来和感觉像锚点但不链接到某些 URL 的东西,请使用具有适当样式和ClickHandler
的 Label 或 HTML;不要滥用锚点来处理非链接的内容。See http://code.google.com/p/google-web-toolkit/issues/detail?id=4502
But the thing is that you shouldn't use an Anchor if you don't have an
href
to set on it. If you want something that looks and feels like an anchor but doesn't link to some URL, then use a Label or HTML with the appropriate styling and aClickHandler
; don't abuse anchors for things that aren't links.