- A+
所属分类:脚本语言
通过事件的which可以找到键码
不过当有组合键的时候还需要注意一下
如ctrl+enter键,虽然都是用e.ctrlKey但是 enter键的键码不是始终为13了
在ff中 判断 ctrl+enter 是 e.ctrlKey && e.which ==13
在ie中 判断ctrl+enter 是 e.ctrlKey && e.which ==10
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Web开发者 - admin10000.com</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$("#txtCommBody").keypress(function(e){
if(e.ctrlKey && e.which == 13 || e.which == 10) {
$("#commForm").submit();
}
})
});
</script>
</head>
<body>
<form id="commForm" method="post" action="">
<textarea id="txtCommBody" name="CommBody" cols="60" rows="10"></textarea>
</form>
</body>
</html>
QQ群: WEB开发者官方总群(196171896) 验证消息:Admin10000




