用js代码创建html标签
appendChild方法可以向一个标签中添加子标签
<head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> window.onload = function () { var divObj = document.createElement("div"); divObj.innerHTML = "子涵真帅"; document.body.appendChild(divObj); } </script> </head> <body> </body>
documen.creatTextNode 创建文本节点
document.body.appendChild(document.createElement("br")); document.body.appendChild(document.createTextNode("子涵真帅"));