我不得不動態地將內容添加到由我的CMS在其論壇模塊中生成的iFrame。我無法控制HTML。我正在動態添加內容並試圖找到最佳解決方案。一起使用jQuery .append和.html
這裏是我使用的代碼:
HTML
<iframe id="re_contentIframe">
<html>
<body>
<p>Forum content is typed here.</p>
<p>More forum content.</p>
Forum Signature
</body>
</html>
</iframe>
JS
nestedFrame = myFrame.find('#re_contentIframe').contents().find('body');
nestedFrame.append("Dynamic content" + data); //this is what is inserted dynamically.
這是我遇到的問題。因爲我無法爲iFrame的控制代碼我CMS生成因爲這樣我結束了,當我使用上面的代碼中有這樣的事情:
Forum Signature Dynamic content...
我想下面的Forum Signature
添加動態內容。然後我厭倦了這樣:
nestedFrame.html("Dynamic content" + data); //this is what is inserted dynamically.
當我做這個論壇的內容是由.html
抹去我又試圖這樣的:
nestedFrame.append(" <br> Dynamic content" + data);
當我這樣做,它打印<br>
。
這裏是我的問題:
是否有辦法追加HTML到目標,而不擦HTML是嗎?我無法想出辦法做到這一點。
嘗試'nestedFrame.append($。parseHTML(「
動態內容」+ data));'或展開並使用'inserAdjacentHTML()' – megawac
@megawac - '$ .parseHTML'工作。請作爲答覆發佈。謝謝! – L84