Javascript捕获密钥 [英] Javascript capture key

查看:85
本文介绍了Javascript捕获密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript从textarea中删除回车键。问题是虽然我能够发现按下输入键,但我无法避免它进入textarea。我不希望输入键即\ n显示在文本区域中。

I am trying to catpure the enter key from a textarea using javascript. The problem is that although I am able to find out that the "enter" key was pressed, I am not unable to avoid it from coming in the textarea. I dont want the enter key i.e. "\n" to be displayed in the text area.

有关如何实现这一点的任何建议吗?

Any suggestions on how to achieve that?

谢谢。

推荐答案

尝试将此功能设置为文本区域的onKeyDown事件:

Try setting this function as the onKeyDown event for the text area:

ex: onkeydown =javascript:return fnIgnoreEnter(event);

function fnIgnoreEnter(thisEvent) {
  if (thisEvent.keyCode == 13) { // enter key
    return false; // do nothing
  }
}

这篇关于Javascript捕获密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆