鍵盤點擊事件,鍵盤事件
接angluarjs自訂標籤,添加鍵盤點擊事件。
//鍵盤事件$scope.keyCheck = function(){//console.log(window.event.keyCode);//第一行是否選中var firstcheck=$("#"+tableuniqueflag+"2").hasClass("checktrcolor");//表格是否有行選中,ischecktr數組var ischecktr=$("#table"+tableuniqueflag+"").find(".checktrcolor");//向上方向鍵if (window.event.keyCode==38) {if(ischecktr.length!=0){//取選中行的id屬性值 <tr id="a2">...</tr>var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id");//第一列名,所以當行數為不等於2時,選中行id=id-1;if(parseInt(checkrowid.substring(1,2))!=2){var nextcheckrowid= parseInt(checkrowid.substring(1,2))-1;$("#"+tableuniqueflag+nextcheckrowid).parent().children().removeClass("checktrcolor");$("#"+tableuniqueflag+nextcheckrowid).addClass("checktrcolor");}}}//向下方向鍵if (window.event.keyCode== 40){if(ischecktr.length!=0){//取選中行的id屬性值,<tr id="a3"> ...</tr> var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id");//當不是最後一行時,選中行id=id+1if(parseInt(checkrowid.substring(1,2))!=rows){var nextcheckrowid= parseInt(checkrowid.substring(1,2))+1;$("#"+tableuniqueflag+nextcheckrowid).parent().children().removeClass("checktrcolor");$("#"+tableuniqueflag+nextcheckrowid).addClass("checktrcolor");}}else if(!firstcheck){//第一次點擊向下的方向鍵,選中第二行資料(第一列名行)$("#"+tableuniqueflag+"2").addClass("checktrcolor")}}//斷行符號鍵if (window.event.keyCode== 13){var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id");var tridcheck=parseInt(checkrowid.substring(1,2));if(ischecktr.length!=0){$scope.selectRow(tridcheck);}}}//失去焦點$scope.inputblur = function(){var checkrowid=$("#table"+tableuniqueflag+"").find(".checktrcolor").attr("id");//a2//判斷是否有選中行if(checkrowid!=""){//去掉表格行的選中狀態$("#"+checkrowid).parent().children().removeClass("checktrcolor");}$(mydivlocation).css('display','none');}
上一文章修改的input
replacetagTemplate='<input type="text" id=inputable'+""+tableuniqueflag+' ng-keyup="showtablediv();" ng-keydown="keyCheck()" ng-blur="inputblur();"></input>';
$scope.showtablediv= function (){...略//方向鍵和斷行符號鍵不觸發,防止選中之後重新觸發建立表格函數if(keycode=="37"||keycode=="38"||keycode=="39"||keycode=="40"||keycode=="13"){return;}...略$scope.createMyTable(rows,cells);...略}
著作權聲明:本文為博主原創文章,未經博主允許不得轉載。