Textarea Adding Space To Beginning of Text?

随声附和 提交于 2019-12-12 13:07:48

问题


I'm having a strange problem in that I have php inserting text into a <textarea> and the <textarea> is adding one white space to the top of my text.

I created an example page to display the problem... here it the code behind the page.

<textarea style="width:600px;height:100px;"><?php get_film_info('main description'); ?></textarea>
<br>
<textarea id="mainDescription style="width:600px;height:100px;">Text just typed in</textarea>
<br>
<?php get_film_info('main description'); ?>

You can see that without the <textarea> tag, the text does not include the indent. My database also reflects no indent, as well as the php output outside of the <textarea>...

Any clue what could be going on?

the sample page

Edit: You were all right, of course I didn't bother checking the source code of the output file. Turns out when I was adding the data (via ajax) I was sending my data like var data = '&main_description= ' + mainDescription. Notice the space between the "=" and the "+".

Thank you all for your input, gotta just give the check mark to the guy on the top of the list.


回答1:


There's definitely a space in the beginning and one at the end, as can be seen in the page source. Perhaps get_film_info() is inadvertently injecting them.




回答2:


Try this:

trim(get_film_info('main description'));



回答3:


Your text has space at beginning! I don't know what function 'get_film_info' returns but it returns with space!




回答4:


There is a heading space in the return value of get_form_info(). Check the value of 'main description' in your database (or whereever it is being stored). If there isn't a heading space in the value itself, then get_film_inflo() is to blame.




回答5:


A space does exist. Outside of the textarea, the browser does not interpret them, because a \n means nothing (it is interpreted in the source code only) in just regular text form. However, a \n inside a textarea represents a line break and is being interpreted as such.

To solve the problem you can always trim the value before outputting it.



来源:https://stackoverflow.com/questions/2457275/textarea-adding-space-to-beginning-of-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!