我想突出顯示單擊時所有行,例如相同的數據。當1b點擊 - >突出顯示行:2和4.當Bev點擊 - >突出顯示行:3和4突出顯示錶中所有行在單擊時所有具有相同數據的行
再次點擊 - >行突出顯示消失。
btw。請注意,懸停效果在跨行時也適用。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
table {border-collapse:collapse; border: 1px solid black;}
td {padding: 5px; border: 1px solid black;}
tr:hover, .hover {background: #eee;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var maximumCells = 0;
var amountOfCells = 0;
var foundCells;
$("tr").each(function() {
foundCells = $(this).find("td");
amountOfCells = foundCells.length;
if (amountOfCells > maximumCells) maximumCells = amountOfCells;
});
$("td").hover(function() {
$el = $(this);
if ($el.siblings("td").length < (maximumCells-1)) {
$el.parent().prev().find("td[rowspan]").addClass("hover");
}
}, function() {
$el.parent().prev().find("td[rowspan]").removeClass("hover");
});
});
</script>
</head>
<body>
<table>
<tr>
<th>lesson</th>
<th>class</th>
<th>absent</th>
<th>substitute</th>
</tr>
<tr>
<td>1</td>
<td>---</td>
<td>---</td>
<td>---</td>
</tr>
<tr>
<td rowspan="2">2</td>
<td>1b</td>
<td>John</td>
<td>Max</td>
</tr>
<tr>
<td>3a</td>
<td>Bev</td>
<td>Abbi</td>
</tr>
<tr>
<td>3</td>
<td>1b</td>
<td>Bev</td>
<td>Robbie</td>
</tr>
</table>
</body>
</html>
會是這樣的,如果任何文本匹配,那麼這些行將突出顯示? – Subhajit
@Subhajit我認爲是的 –