如何将表tr变成链接?
这是我当前的解决方案:
<tr onclick="window.location = '/info/{{ match.login.id }}/'">
<td>{% if match.image %}<img src="{{ match.image|crop:'64x64' }}" alt="Match Avatar" />{% endif %}</td>
<td>{{ match.team_name }}</td>
<td>{{ model|distance_to:match }} {{ model.display_distance }}</td>
<td>{% for expertise in match.expertise_list %}
<span{% if expertise in model.expertise_list %} class="match"{% endif %}>{{ expertise }}</span><br />
{% endfor %}</td>
<td>{% if model|active_connection_with:match %}{{ model|status_with:match }}{% else %}<a href="javascript:connect({{ match.login.id }})" class="button">Connect</a>{% endif %}</td>
但问题是我希望能够右键单击并复制链接等。我该如何实现这一点?
Here is my current solution:
<tr onclick="window.location = '/info/{{ match.login.id }}/'">
<td>{% if match.image %}<img src="{{ match.image|crop:'64x64' }}" alt="Match Avatar" />{% endif %}</td>
<td>{{ match.team_name }}</td>
<td>{{ model|distance_to:match }} {{ model.display_distance }}</td>
<td>{% for expertise in match.expertise_list %}
<span{% if expertise in model.expertise_list %} class="match"{% endif %}>{{ expertise }}</span><br />
{% endfor %}</td>
<td>{% if model|active_connection_with:match %}{{ model|status_with:match }}{% else %}<a href="javascript:connect({{ match.login.id }})" class="button">Connect</a>{% endif %}</td>
But the thing that is wrong with this is that I want to be able to right click and copy link etc. How can i accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
右键单击复制链接仅适用于
A
标记。您必须编写自己的右键单击处理程序。Right-click to copy a link only works on the
A
tag. You'd have to write your own right-click hander.当表元素(tr、td、th)之间有 HTML 元素时,它是无效标记(并且在浏览器上不起作用)。
如果您的表格单元格太复杂而无法标记为链接,您可以做的是使用一个不可见的
元素来覆盖您想要的每个
想要链接:
演示:http://jsfiddle.net/waitinforatrain/puTbj/1/
唯一的缺点是用户无法选择其下方的文本。
It's invalid markup (and doesn't work on browsers) when you have HTML elements between table elements (tr, td, th).
If your table cells are too complicated to mark up as a link, what you can do is have an invisible
<a>
element that covers each<td>
that you want to link:Demo: http://jsfiddle.net/waitinforatrain/puTbj/1/
The only downside is that users can't select the text under it.