我創建了一個帶有 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>
表的類(使用 createElement 創建)在此代碼中無法正常工作
喵喔喔
2022-07-01 16:07:32