This question already has answers here:
Why is textarea filled with mysterious white spaces?
(21个答案)
三年前关闭。
我有
文本区域。我将一个默认值从一个文件加载到其中(d5),但是由于某些原因,它在该值前面给了我很多空间。
php - 默认值TextArea神秘空间-LMLPHP
我试过了
菲律宾比索
    $filename = public_path().'/file/external/header.txt';
    $handle = fopen($filename, "r");
    $header = fread($handle, filesize($filename));
    fclose($handle);

刀片
<div class="form-group">
    <label class="col-sm-12 control-label">Description</label>
    <div class="col-sm-12">
        <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
            {{$description}}
        </textarea>
    </div>
</div>

尝试#2
从我父母那下课。
<div class="form-group">
  <label class="col-sm-12 control-label">Description</label>
  <div class="col-sm-12">
    <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
      {{$description}}
    </textarea>
  </div>
</div>

我得到了
php - 默认值TextArea神秘空间-LMLPHP
尝试#3
从我的文本区域元素中删除类form-group
<div class="">
  <label class="col-sm-12 control-label">Description</label>
  <div class="col-sm-12">
    <textarea name="description" class="" rows="5" placeholder="Desciption">
      {{$description}}
    </textarea>
  </div>
</div>

我得到了
php - 默认值TextArea神秘空间-LMLPHP
为什么会这样?
我做错什么了吗?
我该怎么阻止?

最佳答案

html中有缩进。在打开/关闭<textarea>标签之间出现的任何内容都成为文本区域的一部分:

<div class="col-sm-12">
    <textarea name="description" class="form-control" rows="5" placeholder="Desciption">
                                                                                        ^
        {{$description}}
^^^^^^^^                ^
    </textarea>
^^^^
</div>

标记你得到的空间。如果你不想要这些空间,那就不要它们:
<textarea>foo</textarea>

副总统。
<textarea>
          ^--line break at start of textarea content
    foo
^^^^----spaces
       ^--another line break
</textarea>

关于php - 默认值TextArea神秘空间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35296350/

10-12 00:09
查看更多