[英]How to enable anchor tag on a table row?
<div class="table-responsive">
<table class="table table-bordered">
<tbody>
<tr>
<th>head1</th>
<th>head2</th>
<th>head3</th>
<th>head4</th>
<th>head5</th>
<th>head6</th>
<th>head7</th>
</tr>
<a href="#">
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
<td>col4</td>
<td>col5</td>
<td>col6</td>
<td>col7</td>
</tr>
</a>
</tbody>
</table>
</div>
I have got this html page and i need to make the entire row as an anchor tag so when i hover over the row and click it I can goto another page. 我有这个html页面,我需要将整个行作为锚标记,因此当我将鼠标悬停在该行上并单击它时,可以转到另一个页面。 But When i try to execute it, the DOM throws the anchor tag outside table tags and it does not work.
但是当我尝试执行它时,DOM在表标签之外抛出了锚标签,并且它不起作用。 How can i implement this ?
我该如何实施呢?
You can't add <a>
tag in a <table>
. 您不能在
<table>
添加<a>
标记。 You can only add content in <td>
tag. 您只能在
<td>
标记中添加内容。
Try to add a onclick
attribute with document.location.href+='#anchor'; return false;
尝试使用
document.location.href+='#anchor'; return false;
添加onclick
属性document.location.href+='#anchor'; return false;
document.location.href+='#anchor'; return false;
Example 例
table { height:200px; } #test{ height:400px; background-color:grey; }
<table> <tr onclick="document.location+='#test';return false;"> <td> click </td> <td> click </td> </tr> </table> <div class="test" id="test"></div>
Update 更新资料
For go to another page use 转到另一页使用
window.location.href="url";
instead of 代替
document.location
You can't. 你不能
A link can exist inside a table cell or completely contain a table. 链接可以存在于表格单元内,也可以完全包含表格。 There are no options in between.
两者之间没有选择。
You could put a link in the first cell and then apply some JavaScript: 您可以在第一个单元格中放置一个链接,然后应用一些JavaScript:
jQuery("tr").on("click", function (e) {
location = jQuery(this).find("a").attr("href");
});
It is not a valid standard. 这不是有效的标准。 You can use JS for acnchor.
您可以将JS用作锚点。 For example:
例如:
$('.table-bordered tr td').on("click", function(){
window.location.href= $(this).parent().attr('href');
});
TR defination can be: TR定义可以是:
<tr href="http:/www.yahoo.com">.....</tr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.