我想將一個網站的內容封裝在一個div中(我正在編寫一個用戶同意這種情況的插件)。我做了這樣的:使用jQuery打破頁面包裝正文內容
jQuery("body").append(jQuery('<div id="site-content"></div>')); jQuery("body").children(':not(#site-content)').wrap(jQuery('#site-content'));
出於某種原因,它打破了這個網站:
http://coding.smashingmagazine.com/2012/11/05/writing-fast-memory-efficient-javascript/
這是爲什麼,是有周圍的辦法嗎?
編輯
好吧,$.wrap
是不太我想要的東西,但即使你只是使用appendTo
移動內容仍然無法正常工作。
例子:
jQuery("body").append(jQuery('<div id="site-content"></div>')); jQuery("body").children(':not(#site-content)').appendTo(jQuery('#site-content'))
這是會發生什麼(我的意思打破網站)
這裏的代碼,沒有jQuery的原理:
var contentWrapper, contentContainer, ps_header, node, domSkip = 0, disallowedTags = {
"SCRIPT": null,
"STYLE": null
};
//Create contentWrapper
(contentWrapper = document.createElement("div")).className = document.body.className + " content-wrapper";
(contentContainer = document.createElement("div")).className = "content-container";
contentWrapper.appendChild(contentContainer);
//Populate contentWrapper with the body, while removing it from the body
while (document.body.children.length > domSkip) {
node = document.body.children[domSkip];
if (node.nodeName in disallowedTags) {
domSkip++;
continue;
}
document.body.removeChild(node);
contentContainer.appendChild(node);
}
//Now drop contentWrapper into the DOM
document.body.appendChild(contentWrapper);
你是什麼意思與「休息頁」? – Sergio
在那個頁面的控制檯上執行,你會看到 – LordZardeck
這沒有錯誤,它打破了網站 – LordZardeck