无法在textarea上禁用enter键

时间:2011-05-28 18:03:39

标签: javascript forms spring-mvc java-ee

嗨,伙计们 我正在尝试禁用输入密钥以在textarea中提交表单

使用以下功能:

function noenter() {
    return !(window.event && window.event.keyCode == 13); 
    }

html代码:

<form:form modelAttribute="myObject" method="post" action="${myUrl}">
 <form:textarea path="name" class="new_obj submits_on_return" cols="40" rows="3"  onkeypress="return noenter()"></form:textarea>

但它根本不起作用,它总是提交,任何想法为什么?

1 个答案:

答案 0 :(得分:5)

<script language="JavaScript">
function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}
</script>