【问题标题】:HTML rowspan not working with JavascriptHTML 行跨度不适用于 Javascript
【发布时间】:2014-10-03 04:03:51
【问题描述】:

我正在使用 javascript 创建一个表,其中一些行是我想要的 rowspan,但它不起作用。例如,如果一行的行跨度为 4,那么它在 Mozzila Firefox 中最多只显示 2 个行跨度。但它谷歌浏览器根本不起作用。

    if (currentLectures.length === 1) { //If there is only one element in the array.
          start = currentLectures[0].start;
          end = currentLectures[0].end;
          alert(end);

          rowspan = end - start;   //Rowspan if the lecture times are more than one hour.
          column = document.createElement("td"); //Creating a <td> element.
          column.setAttribute("class", "lectures");
          column.setAttribute("rowspan", rowspan);

          lecture = document.createTextNode(currentLectures[0].name);

          column.appendChild(lecture);
          tableRow.appendChild(column); //Adding the <td> element to the current row.

    }

这是我得到的 html 输出:

        <tbody>
            <tr>
                <th></th>
                <td></td>
                <td></td>
                <td class="lectures"></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>

        <tbody>
            <tr>
                <th>
                    12:00
                </th>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>

我不确定为什么行跨度在这里不起作用。有任何想法吗?

【问题讨论】:

  • 您是否验证过if 语句的内部实际上正在执行?
  • @JLRishe 是的,我可以看到表格

标签: javascript html


【解决方案1】:
var column = document.createElement("td"); //Creating a <td> element.
column.innerHTML = '3';
column.rowSpan = 2
document.getElementById("tr_demo").appendChild(column);

试试?

http://jsfiddle.net/exrw1o2p/

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2011-01-30
    • 1970-01-01
    相关资源
    最近更新 更多