jQuery 箭头键控函数在表的最后一行添加文本框时停止
jQuery arrow keyup function stop while adding a textbox in last row in my table
这是我的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
。而不是仅将事件添加到现有input
的$('input').keyup(fn)
使用$(document).on('keyup', 'input', fn)
。它侦听文档,并在到达每个input
选择器时触发。API 文档中的示例。
相关文章:
- 拆分文本以每隔n个字符添加一行新行,并注意空格
- 如何在jquery菜单中的li项下添加一行
- 使用 javascript 在表中动态添加一行,模糊表中的最后一行
- 如何向 Javascript 表添加一行,其中包含包含 jQuery 中的日期选择器函数的单元格
- SVG - 使用 Javascript 添加一行
- 当我添加一行时无法阻止表单提交
- 试图让JavaScript触发PHP脚本向表中添加一行,但它'It’不起作用
- 在用slim编写的ruby站点中添加一行javascript
- javascript如何每隔四个单元格添加一行
- 如何添加一行新的文本框并下拉
- 在表的每行之后添加一行
- 我如何添加一行到HTML表单
- 使用UJS动态地向表中添加一行
- jqGrid,如何通过模态形式在网格内的任何位置添加一行
- 如何添加一行代码来帮助调试Javascript
- 如果出现警告框,我不希望向表中添加一行
- Javascript在添加一行代码时会崩溃
- Spring MVC向JSP动态添加一行.javascript Vs控制器
- 使用slideDown()向jquery数据表添加一行
- js:在凸出的文本上添加一行