鍵盤點擊事件,鍵盤事件

來源:互聯網
上載者:User

鍵盤點擊事件,鍵盤事件

接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);...略}




著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.