【发布时间】:2018-02-16 19:57:55
【问题描述】:
我会尽量做到具体。当鼠标悬停在使用所有 CSS 的行上时,我有一个表格可以完美地突出显示行。我希望用户能够然后单击一行并使其突出显示,直到单击另一行。下面是一些示例代码和我用来突出显示的 CSS。作为参考,这是一个 MVC 应用程序,它解释了...
@foreach (var item in Model) { }
...开头
function HilightRowOnClick() {
//alert($(row).closest('tr').index())
$(document).ready(function () {
$('tr').click(function () {
//if (this.style.background == "" || this.style.background == "#badecc") {
if (this.style.backgroundColor == "#badecc") {
alert($("Color is normal?"));
$(this).css('background', 'burlywood');
}
else {
$(this).css('background', '#badecc');
alert("Color is not normal?");
}
});
});
}
.DBTable {
width: 100%;
}
.DBToprow {
font-size: 180%;
font-weight: 600;
}
.DBTable td {
font-size: 50%;
padding: 7px;
}
.DBTable th {
border-style: solid;
border-width: 1px;
padding: 7px;
}
.DBTable tr {
background: #badecc;
border-style: solid;
border-width: 1px;
}
.DBTable tr:hover {
background-color: burlywood;
}
<table class="DBTable">
<tr class="DBToprow">
<td></td>
<td>
@Html.DisplayNameFor(model => model.ClientID)
</td>
<td>
@Html.DisplayNameFor(model => model.Active)
</td>
<td>
@Html.DisplayNameFor(model => model.BankID)
</td>
</tr>
@foreach (var item in Model)
{
<tr onclick="HilightRowOnClick()">
<th>
@Html.DisplayFor(modelItem => item.ClientID)
</th>
<th>
@Html.DisplayFor(modelItem => item.Active)
</th>
<th>
@Html.DisplayFor(modelItem => item.BankID)
</th>
</tr>
}
</table>
【问题讨论】:
标签: javascript jquery html css asp.net-mvc