我有一个简单的文本区域,像这样的形式:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink">
<?php if($siteLink_val) echo $siteLink_val; ?>
</textarea>
我一直在这个文本区域得到额外的空白。当我tab到它,我的光标就像在文本区域的中间,而不是在开始?怎么解释呢?
我有一个简单的文本区域,像这样的形式:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink">
<?php if($siteLink_val) echo $siteLink_val; ?>
</textarea>
我一直在这个文本区域得到额外的空白。当我tab到它,我的光标就像在文本区域的中间,而不是在开始?怎么解释呢?
当前回答
我也遇到了同样的问题,解决方法很简单:不要开始新的路线!虽然前面的一些答案可以解决这个问题,但其思想没有阐述清楚。 重要的理解是,为了消除意外的空格,永远不要在开始标记之后开始新行。
下面的方法是错误的,会在你的文本内容之前留下很多不必要的空格:
<textarea>
text content // start with a new line will leave a lot of unwanted spaces
</textarea>
正确的做法是:
<textarea>text content //put text content right after your start tag, no new line
</textarea>
其他回答
此外:textarea标签在多行代码中为新行、制表符等显示空格。
只需要在同一行中定义你的和你的close标记。
<textarea class="form-control"
id="newText"
rows="6"
placeholder="Your placeholder here..."
required
name="newText"></textarea>
基本上应该是这样
<textarea>something here with no spaces in the begining</textarea>
如果有一些预定义的空间,让我们说由于代码格式如下
<textarea>.......
....some_variable
</textarea>
点所示的空格在每次提交时不断增加。
除了这样做:
之前:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink">
<?php if($siteLink_val) echo $siteLink_val; ?>
</textarea>
后:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink"><?php if($siteLink_val) echo $siteLink_val; ?></textarea>
我也添加了PHP的trim()方法:
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink"><?php if($siteLink_val) echo trim($siteLink_val); ?></textarea>
请确保后面没有换行符或空格,这是为了确保没有空格或制表符,只需复制并粘贴此代码:)我已经为您修复了它
<textarea style="width:350px; height:80px;" cols="42" rows="5" name="sitelink"><?php if($siteLink_val) echo trim($siteLink_val);?></textarea>