admin管理员组

文章数量:1397093

I have a textarea and I do console.log($("textarea").val()), the result can be

abc

123

And I have an input, i want to concate the value with the value of textarea, like this

input_value

abc

123

I tried <br> but the br will appear which is not I want. How to make newline in concatenation? use \n?

I have a textarea and I do console.log($("textarea").val()), the result can be

abc

123

And I have an input, i want to concate the value with the value of textarea, like this

input_value

abc

123

I tried <br> but the br will appear which is not I want. How to make newline in concatenation? use \n?

Share Improve this question asked Aug 21, 2016 at 13:47 Maria JaneMaria Jane 2,4037 gold badges27 silver badges40 bronze badges 2
  • Did you try \n? what happened? – epascarello Commented Aug 21, 2016 at 13:51
  • You ask for \n but didn't try it? It's workine fine. – mxlse Commented Aug 21, 2016 at 13:51
Add a ment  | 

2 Answers 2

Reset to default 3

Use \n instead of <br>. Like that:

console.log($("input").val() + '\n' + $("textarea").val());

You can try something like this:

alert('abe \n' + 123);

\n Seems to do the trick for you.

Further Reading: http://www.w3schools./jsref/jsref_regexp_newline.asp

本文标签: javascriptadding newline in string concatenationStack Overflow