<! 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,希望能給大家一個參考,也希望大家多多支持武林網。 ,也希望大家多多支持武林網。