【问题标题】:The class of a table (created with createElement) doesn't work correctly in this code表的类(使用 createElement 创建)在此代码中无法正常工作
【发布时间】:2020-04-17 10:01:59
【问题描述】:

我创建了一个带有 document.createElement('table') 的表和一个带有 table.className 的类,但是当我运行代码时,某些属性(如边框颜色和边框折叠)不起作用。我不知道为什么会这样。

我试图弄清楚这是否来自属性、属性类名或其他东西。我真的不知道。

<!DOCTYPE html>

<html>

<head>
    <title>Ejemplo aprenderaprogramar.com</title>
    <meta charset="utf-8">
    <style type="text/css">
        h1 {
            margin-top: 100px;
            text-align: center;
            color: mediumturquoise;
        }

        #div1 {
            width: 400px;
            height: 400px;
            border: solid 1px gray;
            border-radius: 7px;
            margin: 100px auto;
        }

        .tabla{
            width: 300px;
            height: 200px;
            margin: 50px auto;
            border-style: solid  ;
            border-width: 1px;
            border-color:black ;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
            border-collapse: collapse;

        }


    </style>
      <script type="text/javascript">
        window.onload = function () {


            var body = document.getElementsByTagName("body")[0];
            var table = document.createElement("table");
            body.appendChild(table);
            table.className="tabla";

         }

    </script>
</head>

<body>
    <h1>Calendar</h1>

    <div id="div1">

    </div>

</body>

</html>

【问题讨论】:

    标签: javascript css html-table


    【解决方案1】:

    在 .tabla 的 CSS 代码中,border-collapse 和 border-color 相互抵消。也许这就是它似乎没有显示在网页上的原因。

    .tabla {
        border-color:black ;
        border-collapse: collapse;
    }
    

    【讨论】:

    • 非常感谢!我不知道他们互相取消了。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2012-11-04
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多