js添加键盘是快捷键总结

来源:互联网 发布:旅游网络市场调查 编辑:程序博客网 时间:2024/06/06 17:46

//键盘事件$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);}}//ESCif(window.event.keyCode==27){$("#"+tablediv).css('display','none');}//PageUp PageDownif(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);...略}




0 0