<! doctype html public "-// w3c // dtd xhtml 1.1 // en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11 xml: lang = "en"> <head> <meta http-equiv = "content-type" content = "text/html ؛ charset = utf-8"/> title> testing </title> </head> <script type = "text/javascript" id = "testDiv"> </viv> </body> </html>
example.js 文件内容 :
window.onload = function () {var testDiv = document.getElementById ("testDiv") ؛ testDiv.innerhtml = "<p> I incert <em> هذا المحتوى </em>. </p>" ؛}: :
window.onload = function () {var para = document.createElement ("p") ؛ var txt1 = document.createTextNode ("i inserted") ؛ var extasis = document.createElement ("em") ؛ var txt2 = document.createTextNode ("this") ؛ var txt3 = document.createTextNode ("content.") ؛ para.appendchild (txt1) ؛ التركيز. appendchild (txt2) ؛ para.appendchild (التأكيد) ؛ para.appendchild (txt3) ؛ var testDiv = document.getElementById ("testDiv") ؛ TestDiv.AppendChild (الفقرة) ؛}这与在 Div 内动态载入另一个页面非常相似!
以上这篇 JS 把内容动态插入到 div 的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。