JQuery .html() remove line break on IE 8

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:35:00

问题


So I've been trying to decode string with .html() function in jQuery and it work really nice except on IE...

Here is the string I have:

ééé\r\nààà

I want this to be:

ééé\r\nààà

and I currently get after .html() with IE:

ééé ààà

So this seems nice on FF and Chrome but on IE all linebreak are removed. I found an article (http://web.student.tuwien.ac.at/~e0226430/innerHtmlQuirk.html) explaining the problem is with .innerHTML used by .html() function...

I'm actually surprised to not found a topic about that. Is there any solution? Maybe do a specific function to decode that on IE?

For more here is the code:

var itemDescription = "ééé\r\nàà&#224";
$('.feeds').find('textarea.description[ifid="' + ifid + '"]').html(itemDescription);

回答1:


Try This:

 var itemDescription = "ééé\\r\\nàà&#224";



回答2:


Actually one solution I found is to do something like that:

itemDescription = itemDescription.replace(/(\r\n|\r|\n)/g, '________BREAK________');
var decodedDescription = $("<div>").html(itemDescription).text();
decodedDescription = decodedDescription.replace(/________BREAK________/g, '\r\n');


来源:https://stackoverflow.com/questions/19538864/jquery-html-remove-line-break-on-ie-8

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