使用jQuery(使用href链接和hover !?)可以创建表行(tr) [英] Making a table row (tr) clickable with jQuery (with an a href link, and hover!?)

查看:112
本文介绍了使用jQuery(使用href链接和hover !?)可以创建表行(tr)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个(希望)快速问题,我有以下HTML代码:

Just a (hopefully) quick question, I have the following HTML code:

<tr>
 <td><img src="img/icons/file_pdf.png"></td>
 <td><a href="../upload/1267473577.pdf">Bulletin 1st March 2010</a></td>
 <td>(01/03/10)</td>
</tr>

理想情况下,我想使用jQuery抓取href链接,

Ideally I'd like a way to grab the a href link using jQuery and make it so that no matter where you click on that particular table row, it will take you to that link.

有什么办法可以做到这一点吗?我可以通过icky内联JavaScript作为一个绝对的最后手段,但是,因为发现了关于jQuery我非常喜欢这样的想法,能够做到这一点干净,不引人注目: - )

Is there any way to do this? I can do it via icky inline JavaScript as an absolute last resort, but since finding out about jQuery I quite like the idea of being able to do this cleanly and unobtrusively :-)

推荐答案

假设它是一个正常链接(不是Javascript触发器),就足够了:

Assuming it's a "normal" link (not a Javascript trigger) this will be sufficient:

$("tr").click(function() {
  window.location.href = $(this).find("a").attr("href");
});

您可能希望以某种方式将此行为传达给用户。最小方法是将光标悬停在该行上方。

You will probably want to communicate this behaviour to the user in some way. The minimal approach would be changing the cursor while hovering over the row.

这篇关于使用jQuery(使用href链接和hover !?)可以创建表行(tr)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆