开发者

HTML: is there any way to make clickable <td> o <tr> tags?

开发者 https://www.devze.com 2023-01-20 16:40 出处:网络
Is th开发者_如何学Pythonere any way to make clickable <td> or <tr> tags?<td><a href=\"foo\">bar</a></td>

Is th开发者_如何学Pythonere any way to make clickable <td> or <tr> tags?


<td><a href="foo">bar</a></td>


<td onclick="window.location = 'index.html';">cell content</td>

index.html above can be any URL or internal page link. Note: the mouse pointer does not turn into a pointing hand when you mouse over the cell using this javascript method, but clicking on the cell does take you to the URL.


To turn non-link tags into links, use @Lie Ryan's answer and put an a into the element.

To be able to link to an element:

Use an a

<a href="#idOfTheElement">Link to the element</a>

and a named point:

<td id="idOfTheElement">contents</td>


<td><a name="foo"/>bar</td>


<td>s can have a JavaScript onclick event.

Other than that, putting an <a> into the table cell, and giving it a fixed width to fill the table (you need to make it display: block for that) is the most reliable way.


If I understood correctly what you mean:

<td id="yourcell">Just a useless cell</td>

...
<a href="yourpage.html#yourcell">link</a>

Reference


Here is the correct way to make it using jquery.

$(document).ready(function() {

$('#tableid tr').click(function() {
    var href = $(this).find("a").attr("href");
    if(href) {
        window.location = href;
    }
 });
});

If you want make all the cells are clickable you need to mention "td" in click function.

0

精彩评论

暂无评论...
验证码 换一张
取 消