如何删除textarea中的额外空间

时间:2022-11-28 23:01:36

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:如何删除textarea中的额外空间

你可以在这里看到问题:

4 个解决方案

#1


35  

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标签在换行符上。它正在读取

#2


3  

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://*.com/a/44773825/3775083

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

#3


1  

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(正如你所做的那样)..这将擦除所有的空格。

#4


1  

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>

#1


35  

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标签在换行符上。它正在读取

#2


3  

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://*.com/a/44773825/3775083

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

#3


1  

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(正如你所做的那样)..这将擦除所有的空格。

#4


1  

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>