Javascript Line Break Textarea

前端 未结 5 1927
忘掉有多难
忘掉有多难 2020-12-18 22:11

I have a text area that I want to pre-populate with some specific text that includes line breaks. I\'m populating the area onLoad but I can\'t get the line breaks to work c

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-18 23:08

    i had tried many ways to break a textarea into an array. used this method, it might not be the best.

    using .split('\n') does not remove the break and it will create whitespace or break when insert into database. therefore, i replace it with

    textarea content:
    12345
    6789


    a = a.replace(/\n|\r\n|\r/g, "
    "); var stringArray = a.split('
    '); for (var i = 0; i < stringArray.length; i++) { var myString = stringArray[i]; myString = myString.replace('
    ', ""); response.write(myString); }

提交回复
热议问题