JS,jQuery 键盘事件及判断光标(兼容firefox写法)


<script language="JavaScript" type="text/javascript">  
function keyDown(event) {   
	var e = window.event || event;
	var k = e.keyCode || e.which || e.charCode;
	//IE,firefox 兼容
	var obj = e.srcElement ? e.srcElement : e.target;
	if(k == "13"){
	  if(obj.id == "groupDescName"){
		alert("Enter groupDescName...");
	   }
	}
}
    
	 document.onkeydown = keyDown;
$(function(){
$(document).keydown(function(event){
   //兼容
    var e = window.event || event;
    var k = e.keyCode || e.which ||e.charCode;
    //IE,firefox 兼容
    var obj = e.srcElement ? e.srcElement : e.target;
	if(k == "13" && obj.id == "hello"){
		alert("keyCode13");
	}
			
    });
});
</script>

<div><input id="hello" type="text" style="width: 200px;" /></div>  

你可能感兴趣的:(JavaScript,jquery)