问题
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