Internet Explorer中的jQuery .load方法和换行问题 [英] Problem with jQuery .load method and newlines in internet Explorer
问题描述
我正在尝试使用jQuery的加载方法加载明文数据。这个明文包括换行符。我将此数据加载到HTML< pre>标签。
I'm trying to load plaintext data using jQuery's load method. This plaintext includes line breaks. I load this data into an HTML <pre> tag.
它适用于我尝试的所有浏览器(Firefox / Linux,[Firefox,Chrome,Opera] / Windows),但Internet Explorer除外原始文件已删除。我试图用Windows换行符和Linux换行符保存文件,但这对于浏览器行为没有任何影响(IE既不是行为不端,也不是其他行为持续行为)。
It works fine in all browsers I tried (Firefox/Linux, [Firefox,Chrome,Opera]/Windows) except for Internet Explorer, where the line breaks from the original file are removed. I've tried to save the file with either Windows line-breaks and Linux line-breaks, but this makes no difference with respect to browser behavior (neither IE, which continues to misbehave, nor the others, which keep behaving).
这是HTML代码:
<div id="data">
<pre></pre>
</div>
这是jQuery调用:
This is the jQuery call:
$(function(){
$("#data pre").load("lorem.txt");
});
推荐答案
...或者您可以替换文本,如果浏览器是IE:
... or you can replace the text if the browser is IE:
$("#data pre").load("lorem.txt", function(response, status, xhr) {
if (status != "error") {
if (($.browser.msie)&&(jQuery.browser.version=="8.0"))
$("#data pre").html(response.replace(/\r\n/g, "<br>"));
}
});
这篇关于Internet Explorer中的jQuery .load方法和换行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!