<! Doctype html public "- // w3c // dtd xhtml 1.1 // en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns = "http://www.w3.org/199/xhtm" xml: lang = "en"> <éadf> <méta http-equiv = "contenu-type" contenu = "text / html; charset = utf-8" /> <itle> test </ title> </ head> <script type = "text / javascrip id = "TestDiv"> </div> </ body> </html>
exemple.js 文件内容 :
window.onload = function () {var testDiv = document.getElementyId ("testDiv"); TestDiv.InnerHtml = "<p> J'ai inséré <em> ce contenu </em>. </p>";}:
window.onload = function () {var para = document.CreateElement ("p"); var txt1 = document.createTextNode ("i inséré"); var emphase = document.CreateElement ("em"); var txt2 = document.createTextNode ("this"); var txt3 = document.CreateTextNode ("Content."); Para.ApendChild (TXT1); emphase.ApendChild (txt2); para.ApendChild (mettant l'accent); Para.ApendChild (txt3); var testDiv = document.getElementById ("testDiv"); TestDiv.ApendChild (para);}这与在 div 内动态载入另一个页面非常相似!
以上这篇 js 把内容动态插入到 div 的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。