Я создаю приложение ASP.net Core MVC. И я использую Bootstrap в своих видах. Я отображаю табличный список и выбираю строку, нажав на него. Теперь я пытаюсь сделать так, чтобы я мог использовать выделенные клавиши строк, чтобы прокрутить таблицу. Выбор строки работает нормально. Но не прокрутка с выделенной линией. В чем моя проблема? < /P>
table {
width: 800px;
max-width: 100%;
}
.active {
background: white
}
td {
padding: 8px
}
.clicked {
background: #0d6efd;
}
tr:nth-child(even) {
padding: 8px
}
< /code>
@using System.Linq;
@model List
@ViewData["Title"] - Re
Some
Surname
Name
Patronymic
Birth
@foreach (var p in Model)
{
@p.LastName
@p.FirstName
@p.Patronymic
@p.Birth.ToString("D")
}
@section scripts {
$("table").on("click", "td", function(e) {
$("table").addClass("active");
$("table tr.clicked").removeClass("clicked");
$(e.target)
.closest("tr")
.addClass("clicked");
});
$(document).keydown(function(e) {
switch (e.which) {
case 38: // up
changeRow("up");
break;
case 40: // down
changeRow("down");
break;
default:
return;
}
e.preventDefault();
});
function changeRow(e) {
var currentRow = $("table tr.clicked");
var nextRow;
if (e == "up"&& !currentRow.is(":first-child")) {
nextRow = currentRow.prev();
} else if (e == "down" && !currentRow.is(":last-child")) {
nextRow = currentRow.next();
}
if(nextRow === undefined)
console.log("Not found nextrow");
return;
nextRow.addClass("clicked");
currentRow.removeClass("clicked");
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ng-of-rows