js添加键盘是快捷键总结
2015-07-24 10:44
701 查看
//键盘事件 $scope.keyCheck = function(){ //开发测试 console.log(window.event.keyCode); //开发测试 var firstcheck=$("#"+tableuniqueflag+"2").hasClass("checktrcolor"); var ischecktr=$("#table"+tableuniqueflag+"").find(".checktrcolor"); //向上方向键 if (window.event.keyCode==38) { if(ischecktr.length!=0){ var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id"); if(parseInt(checkrowid.substring(tableuniqueflaglen))!=2){ var nextcheckrowid= parseInt(checkrowid.substring(tableuniqueflaglen))-1; $("#"+tableuniqueflag+nextcheckrowid).parent().children().removeClass("checktrcolor"); $("#"+tableuniqueflag+nextcheckrowid).addClass("checktrcolor"); } } } //向下方向键 if (window.event.keyCode== 40){ if(ischecktr.length!=0){ var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id"); if(parseInt(checkrowid.substring(tableuniqueflaglen))!=rows){ var nextcheckrowid= parseInt(checkrowid.substring(tableuniqueflaglen))+1; $("#"+tableuniqueflag+nextcheckrowid).parent().children().removeClass("checktrcolor"); $("#"+tableuniqueflag+nextcheckrowid).addClass("checktrcolor"); } }else if(!firstcheck){ $("#"+tableuniqueflag+"2").addClass("checktrcolor") } } //回车键 if (window.event.keyCode== 13||window.event.keyCode==9){ var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id"); var tridcheck=parseInt(checkrowid.substring(tableuniqueflaglen)); if(ischecktr.length!=0){ $scope.selectRow(tridcheck); } } //ESC if(window.event.keyCode==27){ $("#"+tablediv).css('display','none'); } //PageUp PageDown if(window.event.keyCode==33){ console.log("pageUp..."); var currentPage =$("#"+tableid).find("#currentPage").text(); var countPage =$("#"+tableid).find("#countPage").text(); var currentPagenum=currentPage.replace(/[^0-9]/ig,""); var countPagenum=countPage.replace(/[^0-9]/ig,""); if(parseInt(currentPagenum)<parseInt(countPagenum)){ //当前页<总页数 $scope.queryCenterReimbursData(keyword,tablequerycols,(parseInt(currentPagenum)+1)); } }else if(window.event.keyCode==34){ var currentPage =$("#"+tableid).find("#currentPage").text(); var countPage =$("#"+tableid).find("#countPage").text(); var currentPagenum=currentPage.replace(/[^0-9]/ig,""); var countPagenum=countPage.replace(/[^0-9]/ig,""); if(parseInt(currentPagenum)>1){ //当前页>1 $scope.queryCenterReimbursData(keyword,tablequerycols,(parseInt(currentPagenum)-1)); } } }
keydown可用于添加快捷键。
keyup可以用于实时查询、校验数据。
上一文章修改的input
<input type="text" id=inputable'+""+tableuniqueflag+' name="" value="" ng-keydown="keyCheck();" ng-keyup="showtabledivcr();" ng-focus="focusshowtabledivcr($event);" ng-blur="closewin($event);" ></input>
$scope.showtablediv= function (){ ...略 //方向键和回车键不触发,防止选中之后重新触发创建表格函数 if(keycode=="37"||keycode=="38"||keycode=="39"||keycode=="40"||keycode=="13"){ return; } ...略 $scope.createMyTable(rows,cells); ...略 }
相关文章推荐
- javascript 手势缩放 旋转 拖动支持:hammer.js
- JSTL
- javascript 手势缩放 旋转 拖动支持:hammer.js
- 解析json的两个方法
- Java、HTML、CSS、JSP、JavaScript注释语法
- JavaScript中的枚举
- JavaScript获取浏览器高度和宽度值(documentElement,clientHeight,offsetHeight,scrollHeight,scrollTop,offsetParent,
- js中运算符的优先级
- Extjs Grid 加载数据.分页。传值,
- js的类型及判断undefined
- JavaScript权威指南_136_第15章_脚本化文档_15.8-文档和元素的几何形状和滚动-滚动
- js实现定时任务,每隔N秒请求后台
- Javascript的UT测试框架-Jasmine简介
- jsp自动刷新(转)
- 使用Html5和Js进行拖动
- javascript 小练习-tab切换
- JS写的排序算法演示
- codeMirror插件使用
- CEF-JavaScriptIntegration
- extjs 去除字符串两边的空格: