当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


HTML DOM Table cellSpacing属性用法及代码示例

HTML DOM Table cellSpacing 属性用于设置或返回 <table> 元素的 cellSpacing 属性的值。 cellSpacing 属性用于定义单元格之间的空间。

注意:HTML5 不再支持此属性。

用法

  • 它返回 cellSpacing 属性。
TableObject.cellSpacing
  • 它用于设置 cellSpacing 属性。
TableObject.cellSpacing = "pixels"

属性值:它包含以像素为单位表示两个单元格之间的空格数的数值。




返回值:它返回一个数值,以像素表示单元格之间的空间。

范例1:下面的代码返回 Table cellSpacing 属性。

HTML


<!DOCTYPE html>
<html>
  
<head>
    <title>
        Table cellSpacing Property in HTML
    </title>
  
    <style>
        table,
        td {
            border:1px solid green;
        }
  
        h1 {
            color:green;
        }
  
        h2 {
            font-family:Impact;
        }
  
        body {
            text-align:center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>Table cellSpacing Property</h2>
  
    <table id="GFG" align="center" cellspacing="20">
        <thead>
            <tr>
                <th>Subject</th>
                <th>Courses</th>
            </tr>
        </thead>
        <tr>
            <td>Java</td>
            <td>Fork Java</td>
        </tr>
        <tr>
            <td>Python</td>
            <td>Fork Python</td>
        </tr>
        <tr>
            <td>Placements</td>
            <td>Sudo Placement</td>
        </tr>
    </table>
    <br />
  
    <button ondblclick="Table_Caption()">
        Return CellPadding
    </button>
      
    <p id="sudo"></p>
  
  
    <script>
        function Table_Caption() {
            var w = document.getElementById(
                    "GFG").cellSpacing;
  
            document.getElementById(
                "sudo").innerHTML = w + "PX";
        }
    </script>
</body>
  
</html>

输出:

范例2:下面的 HTML 代码说明了如何设置 cellSpacing 属性。

HTML


<!DOCTYPE html>
<html>
  
<head>
    <title>
        Table cellSpacing Property in HTML
    </title>
  
    <style>
        table,
        td {
            border:1px solid green;
        }
  
        h1 {
            color:green;
        }
  
        h2 {
            font-family:Impact;
        }
  
        body {
            text-align:center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>Table cellSpacing Property</h2>
  
    <table id="GFG" align="center" cellspacing="20">
        <thead>
            <tr>
                <th>Subject</th>
                <th>Courses</th>
            </tr>
        </thead>
        <tr>
            <td>Java</td>
            <td>Fork Java</td>
        </tr>
        <tr>
            <td>Python</td>
            <td>Fork Python</td>
        </tr>
        <tr>
            <td>Placements</td>
            <td>Sudo Placement</td>
        </tr>
    </table>
    <br />
  
    <button ondblclick="Table_Caption()">
        Return CellPadding
    </button>
      
    <p id="sudo"></p>
  
  
    <script>
        function Table_Caption() {
              
            // Pixel set
            var w = (document.getElementById(
                "GFG").cellSpacing = "5");
  
            document.getElementById(
                "sudo").innerHTML = w + "PX";
        }
    </script>
</body>
  
</html>

输出:

支持的浏览器:

  • 谷歌浏览器
  • Firefox
  • 苹果Safari
  • IE浏览器
  • Opera



相关用法


注:本文由纯净天空筛选整理自ManasChhabra2大神的英文原创作品 HTML DOM Table cellSpacing Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。