美好的一天,添加DIV到iframe主體
我想添加一個DIV標籤到iframe正文。 iframe的內容與我正在處理的網站位於同一個域中,所以這應該不成問題。
<div id="sampleDIV">whatever</div>
<iframe id="custom-frame"></iframe>
而在我的javascript代碼,我有:
// load up the the iframe with the data the user selected
$('#custom-frame').attr("src", "/Custom/Data/" + data.id);
// I can get find the body tag in the iframe like:
var iframeBody = $("#custom-frame").contents().find("body");
var styleTag = iframeBody.append($('#sampleDIV'));
* EDITED * 但當我查看源代碼,我沒有看到div標籤添加。當我在Chrome中檢查元素時,我看不到添加的DIV元素。
*編輯的零件II * 我糾正了標籤從DIV到IFRAME
我看不到我在做什麼錯了,也許就在這個盯着太久。
TIA,
COSON
「查看源文件」:
這對我的作品。它只顯示從服務器下載的原始源代碼。如果你想看到事後修改過的DOM中的任何東西,你需要使用瀏覽器的開發工具。 – jmoerdyk
您需要等待iframe內容加載 –
我輸入的內容不正確。當文檔加載時,我使用Chrome中的Inspect Element查看文檔。 – coson