标签:
接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+1
if(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);
...略
}版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/u010081710/article/details/47037417