<! Doctype html public "-// w3c // dtd xhtml 1.1 // pt" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns = "htttp:/" xml: lang = "pt"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <title> testing </title> </frige> <script type = "text/javasscript" src = "Exemplo.js"> </script> </script> id = "testDiv"> </div> </body> </html>
exemplo.js 文件内容:
window.onload = function () {var testDiv = document.getElementById ("testDiv"); testdiv.innerhtml = "<p> Eu inseri <em> this </em> conteúdo. </p>";}另一段代码
window.onload = function () {var para = document.createElement ("p"); var txt1 = document.createTextNode ("I Inserted"); var ênfase = document.createElement ("em"); var txt2 = document.createTextNode ("this"); var txt3 = document.createTextNode ("content."); para.appendChild (txt1); ênfase.appendChild (txt2); Para.AppendChild (ênfase); para.appendChild (txt3); var testDiv = document.getElementById ("testDiv"); testdiv.appendchild (parágrafo);}这与在 Div 内动态载入另一个页面非常相似!
以上这篇 JS 把内容动态插入到 Div 的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。