There is a text-area where user put some text with 'new lines character', for example:
aaa
bbb
ccc
I would like to copy the value from this textarea to the input but there is a need to keep an information about new lines.
I want to replace new lines with some special separator like NEW_LINE
and then decode it on the backend but something doesn't work, my code is:
var valueFromTextarea = $("#myTextarea").val();
valueFromTextarea .replace(/\n/g,"NEW_LINE");
$("#myTextarea-input").val(valueFromTextarea );
for this code the value of myTextarea-input
is just aaabbbccc
.
How is it possible to resolve that problem?
The replace
method returns the modified value. It doesn't mutate the string (strings are immutable).
You need to pass its return value to val()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.