如何禁用文本区域上的ENTER键? [英] How can I disable the ENTER key on my textarea?

查看:189
本文介绍了如何禁用文本区域上的ENTER键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<form name='qform'>
<textarea name='q' rows='3' cols='60' wrap='hard' id='q' onkeydown="if (event.keyCode == 13) document.getElementById('clickit').click()"></textarea>
<input type='button' value='search' id='clickit' onclick="get();">
</form>

我有此表单...它没有提交按钮,因为我使用的是jquery,并且在此表单下是一个div区域,将在其中显示结果.这是一个搜索引擎,没有输入框,但有一个textarea.这是因为它将是一个多词搜索器.

I have this form... it doesn't have a submit button because I am using jquery and under this form is a div area where the results will be shown. It is a search engine that does not have an input box but instead has a textarea. This is because it will be a multiple word searcher.

问题是,如果我按Enter键,则查询已提交,一切正常……但是对textarea的关注下降了一行,这对我来说是个问题.

The problem is that if I press enter, the query is submitted and everything is ok ... but the focus on textarea goes down one line and that is a problem for me.

基本上,我希望输入仅具有一个功能(提交),而没有其他结束.

Basically I want the enter to have that one function only(submit) end nothing else.

推荐答案

在jquery函数中,使用event.preventdefault,然后执行您喜欢的操作. 例如

In the jquery function, use event.preventdefault and next do what you like. For example

<script>
$("a").click(function(event) {
  event.preventDefault();
//Do your logic here
});
</script>

http://api.jquery.com/event.preventDefault/

这篇关于如何禁用文本区域上的ENTER键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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