English 中文(简体)
• 如何在文字区清除额外空间?
原标题:How to get rid of extra spaces in a textarea?
  • 时间:2011-06-25 15:57:03
  •  标签:
  • php
  • html

我正在形成一种超文本形式,其中载有一些文本领域的代码。

The generated HTML looks like this:

<textarea id="message" name="message"
    rows="18" cols="40">The quick brown fox
    <?php echo $page_url;?>
</textarea>

当该网页放在浏览器上时,它就认为:

The quick brown fox
         http://www.example.com

I cant explain it, since the variable contains no leading spaces - and no CSS styling is being applied either.

谁能想到可能产生这种情况?

最佳回答

<代码><textarea>内的白天空被作为人提供,与超文本不同,后者使连续的白色空间成为一种空间。

<textarea id="message" name="message"
    rows="18" cols="40">The quick brown fox<?php echo $page_url;?></textarea>
问题回答

文本区域尊重空间和断线。 它不同于html文件本身的行为。

There are some spaces (or a tab) on the left of <?php echo ... They will be displayed. Multiple Whitespaces wont get removed in a Textarea.

<textarea id="message" name="message"
    rows="18" cols="40">The quick brown fox
<?php echo $page_url ?>
</textarea>

Simply the fact that you indented you code...

Try that:

<textarea id="message" name="message"
    rows="18" cols="40">The quick brown fox
<?php echo $page_url;?>
</textarea>

空间在文本中保留。

var te = document.createElement( textArea );
te.innerHTML =  asddf   asdf
                  http ;
document.body.appendChild(te);

我刚刚在大火中用粗略的试射法来展示。

To fix you d want something like this

<textarea>some test<?=$var?></textarea>

no need use new line inside the text area, While render it consider new line as some white space.

The text area shows mysterious spaces because it consider all spaces , line breaks (using enter button ) which exists beteen the <textarea> tags. <textarea>
<php? echo $var; ?>
</textarea>
after removing these extra spaces or line breaks it should look as following. <textarea><php? echo $var; ?></textarea>.





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签