[英]How to get the php values of a row on a table in jQuery when clicking on that row?
I have a table with dynamic data from the db, which currently I populate using PHP and I am using href
to navigate when clicking on those values, however, I would like to make the entire row clickable instead of just the text on it.我有一个包含来自 db 的动态数据的表,目前我使用 PHP 填充该表,并且在单击这些值时使用
href
进行导航,但是,我想让整行可单击,而不仅仅是其上的文本。
This is one column how it looks like:这是一列的样子:
<td>
<?php echo '<a href=closed_rma_selected.php?rep_id=' . urlencode($user["id"]) . "&cus_id=" . urlencode($user["cus_id"]) . "&name=" . urlencode($user["name"]) . '>' . $user["id"] . '</a>'; ?>
</td>
Sadly the current html spec doesn't allow interactive elements (like <a>
anchors) to encapsulate table rows.遗憾的是,当前的 html 规范不允许交互式元素(如
<a>
锚点)封装表格行。 And likely will never support it (due to inherit differnece in rendering between cell structures and inline/block type elements)并且可能永远不会支持它(由于继承了单元结构和内联/块类型元素之间的渲染差异)
you can however use Jquery
to do this.但是,您可以使用
Jquery
来执行此操作。
You can acomplish it with the following code:您可以使用以下代码完成它:
Replace values in
{name}
with your unique values将
{name}
中的值替换为您的唯一值
$('#{your tables id}').on('click', 'tr', function () {
var currentElement = $(this);
var destination = currentElement.find(".{classNameOfAnchor}").eq(0).attr('href');
window.location = destination;
});
A codepen for demo purposes: https://codepen.io/yourikoeman/pen/rNxNdJY用于演示目的的代码笔: https://codepen.io/yourikoeman/pen/rNxNdJY
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.