• document基本操作 动态脚本-动态样式-创建表格


    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);
    

      

  • 相关阅读:
    EBS SQL > Form & Report
    oracle sql 优化分析点
    MRP 物料需求计划
    MRPII 制造资源计划
    Barcode128 应用实务
    Oracle SQL语句优化技术分析
    APPSQLAP10710 Online accounting could not be created. AP Invoice 无法创建会计分录
    Oracle数据完整性和锁机制
    ORACLE Responsibility Menu Reference to Other User
    EBS 常用 SQL
  • 原文地址:https://www.cnblogs.com/ms_senda/p/11466397.html
Copyright © 2020-2023  润新知