如何将表tr变成链接?

时间:2011-08-05 20:25:51

标签: javascript html css hyperlink tablerow

这是我目前的解决方案:

<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>

但问题是,我希望能够右键单击并复制链接等。我该如何实现这一目标?

2 个答案:

答案 0 :(得分:2)

右键单击以复制链接仅适用于A标记。您必须编写自己的右键单击手。

答案 1 :(得分:1)

当表元素(tr,td,th)之间有HTML元素时,它是无效的标记(并且在浏览器上不起作用)。

如果您的表格单元格太复杂而无法标记为链接,那么您可以执行的操作是隐藏<a>元素,该元素涵盖您要链接的每个<td>

<table>
    <tr>
        <td>
            <a href="http://google.com" class="overlay"></a>
            Google
        </td>
        <td>
            <a href="http://yahoo.com" class="overlay"></a>
            Yahoo
        </td>
    </tr>

</table>

td {
    position: relative;
}

.overlay {
    background-color: transparent;
    position: absolute;
    width: 100%;
    height: 100%;

}

演示:http://jsfiddle.net/waitinforatrain/puTbj/1/

唯一的缺点是用户无法选择其下的文字。

相关问题