表的类(使用 createElement 创建)在此代码中无法正常工作



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

我想弄清楚这是否来自属性,atribute 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>

在.tablea的CSS代码中,边框折叠边界颜色相互抵消。也许这就是为什么它似乎没有显示在网页上。

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

最新更新