HTML表格是一种用于展示数据的网页元素。表格由行(<tr>
)和列(<td>
)组成。你可以将表格的某一行变成一个链接,当用户点击该行时,会跳转到指定的URL。
<a>
标签。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Row Link Example</title>
</head>
<body>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
<th>Link</th>
</tr>
<tr>
<td>1</td>
<td>John Doe</td>
<td><a href="https://example.com/user/1" target="_blank">View Details</a></td>
</tr>
<tr>
<td>2</td>
<td>Jane Smith</td>
<td><a href="https://example.com/user/2" target="_blank">View Details</a></td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Table Row Link Example</title>
<script>
function openLink(url) {
window.open(url, '_blank');
}
</script>
</head>
<body>
<table border="1">
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr onclick="openLink('https://example.com/user/1')">
<td>1</td>
<td>John Doe</td>
</tr>
<tr onclick="openLink('https://example.com/user/2')">
<td>2</td>
<td>Jane Smith</td>
</tr>
</table>
</body>
</html>
原因:
解决方法:
希望这些信息对你有所帮助!
领取专属 10元无门槛券
手把手带您无忧上云