ExcelKeyEvent.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Namespace.register("U.MD.O.E.KE");
  2. /*
  3. * excel键盘事件总控制函数
  4. */
  5. U.MD.O.E.KE.Control = function () {
  6. U.MD.O.E.KE.cellCut(); //ctrl + x剪切单元格
  7. U.MD.O.E.KE.cellTaste(); //ctrl + v粘贴单元格
  8. U.MD.O.E.KE.cellCopy(); //ctrl + c复制单元格
  9. U.MD.O.E.KE.clearContent(); //backspace删除单元格内容
  10. }
  11. /*
  12. * 复制单元格
  13. */
  14. U.MD.O.E.KE.cellCopy = function () {
  15. $(document).bind("keydown", function (event) {
  16. if (event.ctrlKey && event.keyCode == 67) {
  17. U.MD.O.E.RC.cellCopy();
  18. }
  19. })
  20. }
  21. /*
  22. * 粘贴单元格
  23. */
  24. U.MD.O.E.KE.cellTaste = function () {
  25. $(document).bind("paste", function (event) {
  26. var _content = U.UF.C.pasteText();
  27. var _arr = $$("div");
  28. _arr.innerHTML = _content;
  29. var _arrjson = {};
  30. var _arrcontent = [];
  31. _arrjson.tr = _arr.getElementsByTagName("tr").length;
  32. _arrjson.td = _arr.getElementsByTagName("td").length;
  33. _arrjson.age = _arr.getElementsByTagName("td").length / _arr.getElementsByTagName("tr").length;
  34. for (let i = 0; i < _arr.getElementsByTagName("td").length; i++) {
  35. _arrcontent.push(_arr.getElementsByTagName("td")[i].innerText);
  36. }
  37. U.MD.O.E.RC.cellTaste(_arrjson,_arrcontent);
  38. })
  39. }
  40. /*
  41. * 剪切单元格
  42. */
  43. U.MD.O.E.KE.cellCut = function () {
  44. $(document).bind("keydown", function (event) {
  45. if (event.ctrlKey && event.keyCode == 88) {
  46. U.MD.O.E.RC.cellCut();
  47. }
  48. })
  49. }
  50. /*
  51. * 删除单元格内容
  52. */
  53. U.MD.O.E.KE.clearContent = function () {
  54. $(document).bind("keydown", function (event) {
  55. if (event.keyCode == 8 || event.keyCode == 46) {
  56. U.MD.O.E.RC.clearContent();
  57. }
  58. })
  59. }