简体   繁体   English

我想用shift + enter在textarea中换行

[英]I want to break line in textarea with shift+enter

 <asp:TextBox TextMode="MultiLine" ID="txtComment" runat="server"
  Columns="70" CssClass="commentTxt" onkeypress="getNextElement(this.id,event)"/>                                                       

This is my textbox with textarea . 这是我的textarea文本框。

 <script type="text/javascript">
   function getNextElement(id, e) {
            if (e.keyCode == 13) {
                console.log(e);
                if (e.shiftKey) {

                    return true;
                }
                debugger
                $(":input[id=" + id + "]").next().click();
            }

        }


    </script>

this is my function. 这是我的职责。 When i press shift+enter then it will go to new line in text box 当我按Shift + Enter时,它将转到文本框中的新行

example : - hello
            hi

but when i store this text into database then it will store as hello hi but i want 但是当我将此文本存储到数据库中时,它将以hello hi存储,但是我想要

hello
hi

how can i do this? 我怎样才能做到这一点?

I think you are a bit confused. 我觉得你有点困惑。 If you are saying that the line breaks are not getting saved to the database then you will need to expand on your question a little bit and demonstrate how you are saving the data. 如果您说的是换行符没有保存到数据库中,那么您将需要扩展您的问题并演示如何保存数据。 But, if what you are saying that you CAN'T see the line breaks in tools such as MS SQL Server Management Studio, then don't stress about it because the Query Analyzer's results pane is supposed to be used to preview data with limited formatting...it means that you will not see the line break character(\\n) 但是,如果您说的是在MS SQL Server Management Studio等工具中看不到换行符,则不要着急,因为查询分析器的结果窗格应该用于预览格式受限的数据...这意味着您将看不到换行符(\\ n)

You can use 您可以使用

txtComment.Text.Replace("\r\n", "<br/>")

so when you give enter it replace with <br/> so you will get output as follow 因此,当您输入enter时,请替换为<br/>这样您将获得如下输出

hello<br/>hi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM