我一直试图使表,可以导航到其他行使用箭头键向上/向下。但是当使用向上/向下时,它只起作用一次。之后,突出显示的行不再移动,输入无法填充。
你知道我的代码有什么问题吗?
谢谢
var table = $('#transaksiKasir tr:last');
table.addClass('bg-slate-700 text-white');
$('body').on('keydown', function(e) {
e.preventDefault();
if (e.keyCode == 40) {
table.removeClass('bg-slate-700 text-white');
table.next().addClass('bg-slate-700 text-white')
} else if (e.keyCode == 38) {
table.removeClass('bg-slate-700 text-white');
table.prev().addClass('bg-slate-700 text-white');
}
});
<table class="items-center w-full align-top border-gray-200 text-slate-500 mb-4" id="transaksiKasir">
<thead class="align-bottom">
<tr>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Nama Barang
</th>
<th class="px-6 py-3 pl-2 font-bold uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Harga Jual
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Quantity
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Discount (%)
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Discount (Rp.)
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Subtotal
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Total
</th>
<th class="px-6 py-3 pl-2 font-bold text-left uppercase align-middle bg-transparent border-b border-gray-200 shadow-none text-lg border-b-solid tracking-none whitespace-nowrap text-slate-400 opacity-70">
Action
</th>
</tr>
</thead>
<tbody>
@foreach ($listBarang as $barang)
<tr>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-sm font-semibold leading-tight">
{{ $barang->barang->nama_barang }}
</p>
</td>
<td class="text-center p-2 align-middle bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
{{ IDR($barang->barang->harga_jual) }}
</p>
</td>
<td class="align-middle p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
{{ $barang->qty }}
</p>
</td>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
{{ $barang->discount_persen }}
</p>
</td>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
@isset($barang->discount_value) {{ IDR($barang->discount_value) }} @endisset
</p>
</td>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
{{ IDR($barang->subtotal) }}
</p>
</td>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<p class="mb-0 text-lg font-semibold leading-tight">
{{ IDR($barang->total) }}
</p>
</td>
<td class="p-2 bg-transparent border-b whitespace-nowrap shadow-transparent">
<button wire:click="$emit('openModal', 'kasir.edit-barang',{{ json_encode([" transaksiJualDetail " => $barang->id]) }})" class="py-2 mr-2 px-4 bg-slate-700 text-sm text-white rounded-lg hover:opacity-80 transition duration-300 ease-in-out shadow-sm">
<i class="fa-solid fa-edit"></i>
</button>
<button wire:click="deleteBarang({{$barang->id}})" class="py-2 mr-2 px-4 bg-red-600 text-sm text-white rounded-lg hover:opacity-80 transition duration-300 ease-in-out shadow-sm">
<i class="fa-solid fa-trash"></i>
</button>
</td>
</tr>
@endforeach
</tbody>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
1条答案
按热度按时间zbq4xfa01#
你定义了最后一行将被高亮显示,当你将高亮显示移动到另一行时,你的最后一行不再高亮显示,根据他的说法,你没有起点再次移动高亮显示。
这是工作解决方案: