返回键在< textarea>范围内不起作用 [英] Return key not working within a <textarea>

查看:55
本文介绍了返回键在< textarea>范围内不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net页上定义的textarea遇到问题.在文本区域的后端填充了直接从mssql数据库读取的文本.

I have an issue with a textarea that is defined on an asp.net page. The textarea is populated in the back end with text read directly from an mssql database.

<div id="emailForm" runat="server" style="display:inline;">
  <textarea name="Body" id="Body" rows="20" cols="20">
     text in here
  <textarea>
</div>

以下CSS应用于emailForm div:

The following CSS is applied to the emailForm div:

padding: 5px;
width: 750px;
font-family: Lucida Sans, Verdana, Arial, Helvetica, sans-serif;
font-size: 0.9em;
margin: 0px 0px 10px 0px;
border: 2px solid #ccc;

以及文本区域本身:

height: 360px;

一些用户报告说,尽管他们可以在文本区域内编辑文本,但是他们无法使返回键起作用.无法添加新行?

Some users have reported that whilst they can edit the text within the textarea they cannot get the return key to function. New lines cannot be added?

我已经在网上搜索了,但是找不到这种情况的例子.如果有人有什么好主意,我很想听听.谢谢.

I've search the net but cant find an example of this happening. If anyone has any bright ideas i'd love to hear. Thanks.

推荐答案

要添加到Christoffer的答案中,如果您遇到相同的问题,则可以通过替换以下代码来解决它:

To add to Christoffer's Answer, if you are facing same problem you can solve it by replacing the following code:

$(window).keydown(function(event){
    if(event.keyCode == 13) {
      event.preventDefault();
      return false;
    }
  });

与此:

$(window).keydown(function(event){
    if((event.which== 13) && ($(event.target)[0]!=$("textarea")[0])) {
      event.preventDefault();
      return false;
    }
  });

这将允许textarea输入(换行),而其余部分仍无法使用enter键.

this would allow the textarea to have enter (new line), still preventing the enter key for the rest.

这篇关于返回键在&lt; textarea&gt;范围内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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