js添加键盘是快捷键总结

26 篇文章 0 订阅

//键盘事件
$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);
	...略
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值