zoukankan      html  css  js  c++  java
  • 使用 JS 动态生表格在 IE6 下面的一个小问题

    最近一个项目中需要用到树控件,功能要求挺多的,在网上没有找到现成的,就自己做了一个。

    树是根据相关的数据使用 JS 动态创建的,每一个节点是使用表格来排版的, 所以这里就需要使用到动态创建表格的功能:

    var table = document.createElement("<table border=0 cellpadding=0 cellspacing=0 width=100%>");
    var tr = document.createElement("tr");
    table.appendChild(tr); 

     在 IE6 下面,表格死活不出来,测试了很长时间,最后改成了:

    var table = document.createElement("<table border=0 cellpadding=0 cellspacing=0 width=100%>");
    var tbody = document.createElement('tbody');
    table.appendChild(tbody);

    var tr = document.createElement("tr");

    tbody.appendChild(tr);  

    中间添加了一个 tbody 就没事了。

    写代码写出惯性来了,创建元素的时候只记得 document.createElement 了,都忘记 table 有一个 insertRow 方法。

    使用 insertRow 方法就没有以上的问题:

    var table = document.createElement("<table border=0 cellpadding=0 cellspacing=0 width=100%>");

    var tr = table.insertRow();
    // 不需要把 tr 加到表格里, insertRow 方法已经自动把新添加的行加入到表格了 

  • 相关阅读:
    (22)进程和线程区别
    (21)回调函数
    (20)gevent协程
    (18)ProcessPoolExecutor进程池
    (19)ThreadPoolExecutor线程池
    (17)线程队列---queue LifoQueue PriorityQueue
    (16)线程---定时器Timer
    (15)线程---Condition条件
    (14)线程- Event事件和守护线程Daemon
    IDEA快速搭建WEB项目【记录篇】
  • 原文地址:https://www.cnblogs.com/kuku/p/1602531.html
Copyright © 2011-2022 走看看