//调用:new tabTableInput("tblGrid","text");
var tabTableInput = function (tableId, inputType) {
var rowInputs = [];
var trs = $("#" + tableId).find("tr");
var inputRowIndex = 0;
$.each(trs, function (i, obj) {
if ($(obj).find("th").length > 0) { //跳过表头
return true;
}
var rowArray = [];
var thisRowInputs;
if (!inputType) { //所有的input
thisRowInputs = $(obj).find("input:not(:disabled):not(:hidden):not([readonly])");
} else {
thisRowInputs = $(obj).find("input:not(:disabled):not(:hidden):not([readonly])[type=" + inputType + "]");
}
if (thisRowInputs.length == 0)
return true; thisRowInputs.each(function (j) {
$(this).attr("_r_", inputRowIndex).attr("_c_", j);
rowArray.push({ "c": j, "input": this }); $(this).keydown(function (evt) {
var r = $(this).attr("_r_");
var c = $(this).attr("_c_"); if (evt.which < 37 || evt.which > 40) {
return;
} var tRow
if (evt.which == 38) { //上
if (r == 0)
return; r--; //向上一行 tRow = rowInputs[r];
if (c > tRow.length - 1) {
c = tRow.length - 1;
}
} else if (evt.which == 40) { //下
if (r == rowInputs.length - 1) { //已经是最后一行
return;
} r++;
tRow = rowInputs[r];
if (c > tRow.length - 1) {
c = tRow.length - 1;
}
} else if (evt.which == 37) { //左
if (r == 0 && c == 0) { //第一行第一个,则不执行操作
return;
}
if (c == 0) { //某行的第一个,则要跳到上一行的最后一个,此处保证了r大于0
r--;
tRow = rowInputs[r];
c = tRow.length - 1;
} else { //否则只需向左走一个
c--;
}
} else if (evt.which == 39) { //右
tRow = rowInputs[r];
if (r == rowInputs.length - 1 && c == tRow.length - 1) { //最后一个不执行操作
return;
} if (c == tRow.length - 1) { //当前行的最后一个,跳入下一行的第一个
r++;
c = 0;
} else {
c++;
}
} $(rowInputs[r].data[c].input).focus().select();
});
}); rowInputs.push({ "length": thisRowInputs.length, "rowindex": inputRowIndex, "data": rowArray }); inputRowIndex++;
});
}

最新文章

  1. java反射 之 反射基础
  2. UVALive5031 Graph and Queries(Treap)
  3. Codeforce - Street Lamps
  4. js动态改变时间
  5. poj 2524 并查集 Ubiquitous Religions
  6. android 项目学习随笔十三(ListView实现ITEM点击事件,将已读状态持久化到本地)
  7. Oracle AWR报告自动生成并ftp脚本
  8. UPUPW PHP环境集成包
  9. 怎样合并排序数组(How to merge 2 sorted arrays?)
  10. iOS6和iOS7代码的适配(2)——status bar
  11. Rest分页接口开发
  12. go使用context包避免goroutine泄露问题
  13. 自动化测试基础篇--Selenium中JS处理浏览器弹窗
  14. gei 操作
  15. 系统管理员需知的 16 个 iptables 使用技巧
  16. JavaScript基础要点
  17. 关于素数:求不超过n的素数,素数的判定(Miller Rabin 测试)
  18. [转] React 是什么
  19. [Eclipse]在重命令文件名时,提示编码格式有问题导致修改失败,需要设置如下几个默认编码为UTF-8
  20. Python:Opening Python Classes

热门文章

  1. DroneCI启用privileged
  2. 基于java实现的简单区块链
  3. c# 非调试状态下面执行
  4. kalman滤波
  5. 关于XCode工程中PrefixHead.pch文件的使用
  6. UE4 Notes
  7. svg中实现文字随曲线走向,HTML直接写和JavaScript创建对象两种方式
  8. bugku的一道图片隐写
  9. python3 log 日志记录
  10. Linux配置定时,使用 crontab -e 与 直接编辑 /etc/crontab 的区别