尝试使用 JQuery 突出显示表行但不工作,谁能告诉我为什么以及如何解决它?
桌子:
<table id="customers">
<caption>Customers</caption>
<thead>
<tr>
<th>Customer no</th>
<th>Last name</th>
<th>First name</th>
<th>Options</th>
</tr>
</thead>
<tbody>
<tr class="alt">
<td>1</td>
<td>Jackson</td>
<td>Simon</td>
<td>
<div class="align-left">
<input type="submit" name="View" id="view" value="View" />
</div>
<div class="align-right">
<input type="submit" name="Rent" id="rent" value="Wants to rent" />
</div>
</td>
</tr>
<tr class="alt">
<td>1</td>
<td>Miller</td>
<td>Darren</td>
<td>
<div class="align-left">
<input type="submit" name="View" id="view" value="View" />
</div>
<div class="align-right">
<input type="submit" name="Rent" id="rent" value="Wants to rent" />
</div>
</td>
</tr>
</tbody>
</table>
查询:
$("#customers tbody tr").hover(
function () {
$(this).css({
background: 'yellow'
});
},
function () {
$(this).css("background", "");
});
发生的情况是当将鼠标悬停在表格行上时不会突出显示,另请注意,当我调整选择器时它适用于 td,但不适用于 tr 行。
CSS:
...
/* table data style */
table {
border-collapse: collapse;
width: 400px;
color: grey;
font-family: sans-serif;
}
th, td {
border-bottom: 1px solid brown;
padding: 5px;
background-color: seashell;
text-align: left;
}
th {
width: 200px;
}
td {
width: 200px;
}
tr.alt td, tr.alt th {
background-color: white;
}
tr:last-child td, tr:last-child th {
border-bottom: 0;
}
caption {
font-weight: bold;
padding-bottom: 5px;
}
.main-font {
font-family: sans-serif;
}