Html 如何删除textarea内的多余空间

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24367927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:07:32  来源:igfitidea点击:

How to remove extra space inside textarea

htmltextareawhitespace

提问by user2815059

I have a textarea which displays some data from "history" column in my database. For unknown reason there is nearly 1.5 line of extra space before the text. Anyone can give me some idea why does it happen? Here is my HTML piece:

我有一个 textarea 显示我的数据库中“历史”列中的一些数据。由于未知原因,文本前有近 1.5 行的额外空格。任何人都可以给我一些想法为什么会发生?这是我的 HTML 片段:

<div>
  <table>
    <tr>
      <th > History:</th>
      <td>
        <textarea style="margin-left:90px";  name="history"cols="80"label="notes"rows="4"wrap="virtual"> 
        <?php echo $my_class->history;?></textarea>
      </td> 
    </tr>
  </table>
</div>

You can see the problem here:enter image description here

你可以在这里看到问题:在此处输入图片说明

回答by Revive

Its because your php tag is on a newline. It is reading in the whitespace from where <textarea>ends until php tag opens. Put this all on one line to fix.

这是因为您的 php 标签在换行符上。它从空白处读取, <textarea>直到 php 标签打开。把这一切放在一条线上来解决。

回答by Er Jagdish Patel

I know its late but may help others.

我知道它晚了,但可能会帮助其他人。

use this when document indentation is required.

当需要文档缩进时使用它。

$('document').ready(function()
{
    $('textarea').each(function(){
            $(this).val($(this).val().trim());
        }
    );
});

Same Question : https://stackoverflow.com/a/44773825/3775083

同样的问题:https://stackoverflow.com/a/44773825/3775083

回答by Narendra Solanki

Put this all on one line for fix this issue.Make your code like this.

把这一切放在一行来解决这个问题。让你的代码像这样。

<textarea style="margin-left:90px";name="history"cols="80"label="notes"rows="4"wrap="virtual"><?php echo $my_class->history;?></textarea>

回答by Giorgos Tsakonas

Just put your php open tag right after the textarea close tag.. Dont use line break.. And close php exactly before (as you have done).. This will erase all the whitespaces..

只需将您的 php 打开标签放在 textarea 关闭标签之后.. 不要使用换行符.. 并在之前关闭 php(就像您所做的那样).. 这将删除所有空格..

回答by Sumit Kumar Gupta

I faced same problem but I found an answer of this question. When you write php code between textarea in another line or in new line then this problem occurs

我遇到了同样的问题,但我找到了这个问题的答案。当您在另一行或新行中的 textarea 之间编写 php 代码时,就会出现此问题

To fix this problem write php code and textarea in one line

要解决此问题,请在一行中编写 php 代码和 textarea

<div>
  <table>
    <tr>
      <th > History:</th>
      <td>
        **<textarea name="history"cols="80" label="notes"rows="4" wrap="virtual"><?php echo $my_class->history;?></textarea>**
      </td> 
    </tr>
  </table>
</div>