У меня небольшая проблема, немного отличная от обычных вопросов изменения цвета фона. Mine ссылается на @ html.displayfor вместо обычного значения в элементе td.изменить фон ячейки таблицы в зависимости от значения
Я попытался реализовать сценарий jquery, который изменит цвет ячейки High Priority, если значение этой ячейки равно Yes. Я попробовал реализовать класс в 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>
Почему вы используете селектор "#high. Вы должны использовать селектор классов в зависимости от строки, которую вы смотрите на «.high» – tabz100