douyi8315 2018-05-29 15:03
浏览 391
已采纳

替换textarea换行符以将文本保存到Mysql

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!
  • 写回答

1条回答 默认 最新

  • dongque3797 2018-05-29 15:08
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?