var html = document.documentElement; var body = document.body; window.onload = function() { //document.write("Hello World!"); } var fragment = document.createDocumentFragment(); var ul = document.getElementById("myDiv"); var li = null; for (var i = 0; i < 3; i++) { li = document.createElement("li"); li.appendChild(document.createTextNode("Item" + (i + 1))); fragment.appendChild(li); } ul.appendChild(fragment); //动态创建脚本 var script = document.createElement("script"); script.type = "text/javascript"; script.src = "docment.js"; document.body.appendChild(script); //var attr = document.createAttribute("align"); //动态样式 var link = document.createElement("link"); link.rel = "stylesheet"; link.type = "text/css"; link.href = "style.css"; var head = document.getElementsByTagName("head")[0]; head.appendChild(link); //表格 var table = document.createElement("table"); table.border = 1; table.width = "100%"; //创建tbody var tbody = document.createElement("tbody"); table.appendChild(tbody); //创建行 var row1 = document.createElement("tr"); tbody.appendChild(row1); var cell1 = document.createElement("td"); //创建列 cell1.appendChild(document.createTextNode("cell1 1.1")); //设置列文本内容 row1.appendChild(cell1); //设置列所属行 var cell2 = document.createElement("td"); cell2.appendChild(document.createTextNode("cell2 2.1")); row1.appendChild(cell2); document.body.appendChild(table); //通过属性方法创建表格 var table = document.createElement("table"); table.border = 1; table.width = "100%"; var tbody = document.createElement("tbody"); table.appendChild(body); //创建第一行 tbody.insertRow(0); tbody.rows[0].insertCell(0); tbody.rows[0].cells[0].appendChild(document.createTextNode("Cell 1,1")); tbody.rows[0].insertCell(1); tbody.rows[0].cells[1].appendChild(document.createTextNode("Cell 2,1")); //创建第二行 tbody.insertRow(1); tbody.rows[1].insertCell(0); tbody.rows[1].cells[0].appendChild(document.createTextNode("Cell 1,2")); tbody.rows[1].insertCell(1); tbody.rows[1].cells[1].appendChild(document.createTextNode("Cell 2,2")); document.body.appendChild(table);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。