用Jquery load text文本到網頁遇到的問題

HTML

<div id="divText"></div>

Javascript

$('#divText').load(fileName ,function(responseTxt,statusTxt,xhr){
if(statusTxt=="success")
    alert("success!");
if(statusTxt=="error")
    alert("Error: "+xhr.status+": "+xhr.statusText);
});

1. Chrome和IE 不支援load function (測試用 Google Chrome 版本 34.0.1847.137 m ; IE 版本 11.0.9600.17107)

2. 在FireFox中,文本的中的換行符,在頁面上只顯示一個空格。 (FireFox 版本 29.0.1)

    參考: http://stackoverflow.com/questions/13495748/replace-r-ns-with-br-s

   對空格進行替換成<br />,仍然不可以。

   添加了一句無關緊要的alert語句,竟然解決了。

 alert($('#divText').html()); 
 $('#divText').html($('#divText').text().replace(/
|
|
/g, '<br />'));
原文地址:https://www.cnblogs.com/sipher/p/3756285.html