【发布时间】:2023-03-26 12:30:01
【问题描述】:
我有一个小问题,与通常的背景颜色变化问题略有不同。我指的是 @html.displayfor 而不是 td 元素中的通常值。
我尝试实现一个 jquery 脚本,如果该单元格的值等于是,它将更改高优先级单元格的颜色。我尝试在 displayfor 中实现一个类,但似乎没有什么不同。以下是我有问题的代码部分。
table.js
window.onload = function () {
$("#tfhover").hide().fadeIn(1500);
var tfrow = document.getElementById('tfhover').rows.length;
var tbRow = [];
for (var i = 1; i < tfrow; i++) {
tbRow[i] = document.getElementById('tfhover').rows[i];
tbRow[i].onmouseover = function () {
this.style.backgroundColor = '#ffffff';
};
tbRow[i].onmouseout = function () {
this.style.backgroundColor = '#d4e3e5';
};
if ($('#high').val() == 'Yes') {
this.style.backgroundColor = "#000033";
};
};
};
index.cshtml
<script type="text/javascript" src="~/Scripts/Table.js"></script>
<table id="tfhover" class="tftable" border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.JobID)   
</th>
<th>
@Html.DisplayNameFor(model => model.Order.OrderID)   
</th>
<th>
@Html.DisplayNameFor(model => model.Location.LocationName)   
</th>
<th>
@Html.DisplayNameFor(model => model.Order.EstimatedCompletion)   
</th>
<th>
@Html.DisplayNameFor(model => model.HighPriority)   
</th>
<th>
@Html.DisplayNameFor(model => model.LastUpdated)   
</th>
<th>
@Html.DisplayNameFor(model => model.Comments)   
</th>
<th>
@Html.DisplayNameFor(model => model.Status)   
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.JobID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Order.OrderID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Location.LocationName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Order.EstimatedCompletion)
</td>
<td>
@Html.DisplayFor(modelItem => item.HighPriority, new {@class ="high" })
</td>
<td>
@Html.DisplayFor(modelItem => item.LastUpdated)
</td>
<td>
@Html.DisplayFor(modelItem => item.Comments)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.JobID }) |
@Html.ActionLink("Details", "Details", new { id=item.JobID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.JobID })
</td>
</tr>
}
</table>
【问题讨论】:
-
你为什么使用 id 选择器'#high'。您应该根据您正在查看的“.high”行来使用类选择器
标签: jquery html css model-view-controller