这是我的 jquery 代码,我想继续我的箭头键功能。
$(document).ready(function () {
$('input').keyup(function (e) {
switch (e.keyCode) {
case 37:
// alert('left');
$(this).closest('td').prev().find('input').focus();
break;
case 38:
// alert('up');
$(this).closest('tr').prev().find('td:eq(' + $(this).closest('td').index() + ')').find('input').focus();
break;
case 39:
// alert('right');
$(this).closest('td').next().find('input').focus();
break;
case 40:
// alert('down');
var checkRow = $(this).closest('tr').index() + 1;
var totalRows = $(this).closest('tbody').find('tr').length;
if (checkRow == totalRows)
{
//here's my additional table row
var add= $(this).closest('tr').clone().appendTo($(this).closest('tbody').parent());
//i want to continue arrows key for additional textbox in my new row.
}
$(this).closest('tr').next().find('td:eq(' + $(this).closest('td').index() + ')').find('input').focus();
break;
} }); });
最佳答案
您没有将 keyup
事件添加到新创建的 input
中。使用 $(document).on('keyup', 而不是仅向现有
。它监听文档并在到达每个 input
添加事件的 $('input').keyup(fn)
'输入',fn)input
选择器时触发。 API documentation 中的示例.
关于javascript - jQuery 箭头键功能在我的表格最后一行添加文本框时停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30754581/