<!docype html public“ - // W3C // DTD XHTML 1.1 // en”“” http://www.org/tr/xhtml11/dtd/xhtml11/xhtml11.dtdddddddddddddddddd'> <html xmlns = xml:lang =“ en”> <head> <meta http-equiv =“ content-type” content =“ text/html; charset = utf-8”/> <title> testing> testing </title> </title> </head> </head> <scripty> <scripty =“ text/javascript/javascript/javascript/javascript” id =“ testdiv”> </div> </body> </html>
示例.js文件内容:
window.onload = function(){var testDiv = document.getElementById(“ testDiv”); testdiv.innerhtml =“ <p> i插入<em> this </em> content。</p>”;}另一段代码:
window.onload = function(){var para = document.createelement(“ p”); var txt1 = document.createTextNode(“ i inserted”); var opplasis = 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(para);}这与在div 内动态载入另一个页面非常相似!
以上这篇js把内容动态插入到div,希望能给大家一个参考,也希望大家多多支持武林网。,也希望大家多多支持武林网。