<! doctype html public "-// w3c // dtd xhtml 1.1 // en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd"> <html xmlns = "http://www.w.w.w.org/199/xhtml xml : lang = "en"> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"/> <title> 테스트 </title> </head> <script type = "text/javascript"src = "example.js "> <div id = "tectdiv"> </div> </body> </html>
example.js 文件内容 :
window.onload = function () {var trectdiv = document.getElementById ( "treviv"); readdiv.innerhtml = "<p> 나는 <em> inserted </em> 컨텐츠 </p>";}另一段代码 :
Window.onload = function () {var para = document.createElement ( "p"); var txt1 = document.creatextNode ( "I Inserted"); var ompasis = document.createElement ( "em"); var txt2 = document.creatextNode ( "this"); var txt3 = document.creatextNode ( "Content."); para. AppendChild (txt1); 강조. AppendChild (txt2); para. AppendChild (강조); para. AppendChild (txt3); var trectdiv = document.getElementById ( "treviv"); trev.appendChild (para);}这与在 div 内动态载入另一个页面非常相似!
以上这篇 js 把内容动态插入到 div 的实现方法就是小编分享给大家的全部内容了 的实现方法就是小编分享给大家的全部内容了, 希望能给大家一个参考, 也希望大家多多支持武林网。