<! Doctype html public "-// w3c // dtd xhtml 1.1 // en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns = "http://wwww.w3.org/199999999999/XHTML" xml: lang = "en"> <fead> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> testing </title> </head> <script type = "text/javaScript" src = "ejemplo.js"> </script> <body> id = "testDiv"> </div> </body> </html>
Ejemplo.js 文件内容 :
Window.Onload = function () {var testDiv = document.getElementById ("testDiv"); testDiv.innerhtml = "<p> Isporté <em> este </em> contenido. </p>";}另一段代码 :
window.Onload = function () {var para = document.createElement ("p"); var txt1 = document.createTextNode ("I Inserted"); Var énfasis = document.createElement ("em"); var txt2 = document.createTextNode ("this"); var txt3 = document.createTextNode ("Content."); para.appendchild (txt1); énfasis.appendChild (txt2); para.appendchild (énfasis); para.appendchild (txt3); var testDiv = document.getElementById ("testDiv"); testDiv.appendChild (para);}这与在 Div 内动态载入另一个页面非常相似!
以上这篇 js 把内容动态插入到 div 的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 也希望大家多多支持武林网。