[ revision 2012, no inline handler, preserve textarea enter handling]
([2012年修订版 ,没有内联处理程序,保留textarea输入处理内容])
function checkEnter(e){
e = e || event;
var txtArea = /textarea/i.test((e.target || e.srcElement).tagName);
return txtArea || (e.keyCode || e.which || e.charCode || 0) !== 13;
}
Now you can define a keypress handler on the form:
(现在,您可以在表单上定义按键处理程序:)
<form [...] onkeypress="return checkEnter(event)">
(
<form [...] onkeypress =“ return checkEnter(event)”>
)
document.querySelector('form').onkeypress = checkEnter;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…