我的應用程序中有一個jquery $ .get()調用請求整個網頁。在回調函數中,我訪問返回頁面中的div,獲取其數據並將其顯示在我的頁面上。
問題是我從div得到的文本不保留源格式。如果請求頁面中的div有說出有序列表,那麼當我得到該文本並顯示在我的頁面上時,它會顯示爲帶有內聯項目的段落,而不是顯示爲列表。
我不知道問題是$ .get()是獲取數據還是顯示數據。
//get the page
$.get($(this).attr('href'), function(data){
callbackFunc(data,myLink);
},
"html");
function callbackFunc(responseText, customData){
//response has bg color of #DFDFDF
var td = $("td[bgcolor='#DFDFDF']", responseText);
//text to show is in div of that td
var forumText = $('div', td).text();
//append new row with request data below the current row in my table
var currentRow = $(customData).parent('td').parent('tr');
var toAppend = "<tr><td class='myTd' colspan='3'>" + forumText + "</td></tr>";
$(currentRow).after(toAppend);
}
響應數據顯示像ABC新行我添加到我的div而源頁面的div有
一個
乙
下,在
我要補充一點,這個腳本是部分Google Chrome瀏覽器的擴展程序,因此這是我測試的唯一瀏覽器