I need to replace the newlines in a textarea with the string ", " for storing it in a database. For example, the following string, taken from the textarea:
hi!
line break!
Would be replaced with:
hi!, line break!
I need to replace the newlines in a textarea with the string ", " for storing it in a database. For example, the following string, taken from the textarea:
hi!
line break!
Would be replaced with:
hi!, line break!
收起
Try .value.replace(/
/g, '')
. This will replace all occurrences of new line in the text area with empty string.
var textWithoutLineBreak = document.getElementById('txtArea').value.replace(/
/g,'');
console.log(textWithoutLineBreak);
<textarea id="txtArea">hi!
line break!
</textarea>
</div>
报告相同问题?