\n is not working in IE text area

怎甘沉沦 提交于 2019-12-14 04:20:02

问题


I am using this jquery to add some elements of the page and add them to a text area

$('#chk_editor').append($('#greeting').text()).append('\n \nI want it to be known that').show();

Internet Explorer ignores the /n, I found this question that addresses the issue with split() Javascript split() not working in IE

I'm not sure how to implement it into my code, any help appreciated.


回答1:


Try using \r\n.

This is the Windows style line ending. \n is the UNIX style line ending.




回答2:


Try the following:

    var text = $("#chk_editor").val();
    text = text + $("#greeting").html();
    text = text + "\n \n I want to be known.";
    $("#chk_editor").val(text);



回答3:


try one of those 2 options:

1) for any string that contain \n you can do somthing like:

  function adjustText(messageString)
 {
   return messageString.replace('\n', '\r\n');
 }
 ....
 $('#chk_editor').append($('#greeting').text()).append(adjustText(message));

see also https://stackoverflow.com/a/5899275/1219182

2) try to use the jquery-val() property (when setting textArea) instead of text()

$('#chk_editor').val("some text....\n ...bla bla \n...)

see also https://stackoverflow.com/a/5583094/1219182



来源:https://stackoverflow.com/questions/14633339/n-is-not-working-in-ie-text-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!