HTML DOM 样式 emptyCells 属性

htmlweb developmentfront end technology更新于 2024/3/14 6:04:17

HTML DOM 样式 emptyCells 属性用于指定表格中空单元格的显示方式。默认情况下,此属性设置为 show。

以下是语法 −

设置 emptyCells 属性 −

empty-cells: show|hide|initial|inherit;

此处,"show"会在空单元格上显示边框,"hide"不会显示边框。"initial"将其设置为默认值,"inherit"会继承父级属性值。

让我们来看一个 emptyCells 属性的示例 −

示例

<!DOCTYPE html>
<html>
<head>
<style>
   #TABLE1 {
      font-style: italic;
      empty-cells: hide;
   }
   table,td {
      margin: 5px;
      padding: 3px;
      border: 1px solid black;
   }
</style>
<script>
   function showEmptyCells() {
      document.getElementById("TABLE1").style.emptyCells="show"
      document.getElementById("Sample").innerHTML="The empty cells of the table will now be visible";
   }
</script>
</head>
<body>
   <table id="TABLE1">
      <tr>
         <td>demo</td>
         <td></td>
         <td></td>
      </tr>
      <tr>
         <td>demo</td>
         <td></td>
         <td></td>
      </tr>
      <tr>
         <td>demo</td>
         <td></td>
         <td></td>
      </tr>
   </table>
   <p>Show the hidden cells of the above table by clicking the below button</p>
   <button onclick="showEmptyCells()">Show cells</button>
   <p id="Sample"></p>
</body>
</html>

输出

点击"显示单元格"按钮 −


相关文章


有用资源