Forcing a carriage return in textarea
I would like to start a textarea with inside a text that starts some line under the first line. Doing something like:
var myText = '\r \r \r HELLO';
doesn't work: HELLO is written on the first line, while
var myText = 'HELLO \r \r \r HELLO2';
puts 开发者_如何学编程correctly HELLO2 after HELLO. This means that \r
is correct, but it doesn't work at the beginning of the textarea.
Any suggestions?
Try inserting
into the text area.
Have you tried to put space or
before the "\r"?
Don't use \r, use \n
Example:
var myText = '\n \n \n HELLO';
In PHP I had to make sure to use double quotes instead of single.
$var1 = 'Test1 above /n/n Test below'; //will not work
$var2 = "Test2 above /n/n Test below"; //will work
echo = "<textarea>$var1</textarea><br /><textarea>$var2</textarea>";
"\r" is to return to the begining of the line the, i forgot its name, i think is the cursor. But what you need is "\n" for a new line
If you are using .net.
Then do
Var myText = "Hello" + Enviroment.NewLine + "Hello2";
However if your using something else, i.e. Java, web languages then I advise you try /n
followed by /r
. I have had to use "/n/r"
to get the result I wanted, after the /r
was being ignored.
What browser and/or OS are you using? In my quick test, both \r
and \n
yield the same (correct) result on Windows in IE 8, Firefox 3.6, and Chrome 9.
<textarea rows="5" id="r"></textarea>
<textarea rows="5" id="n"></textarea>
$(function() {
$('#r').val('\r\r\rHello');
$('#n').val('\n\n\nHello');
});
精彩评论