Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีตรวจสอบว่าขอบและพื้นหลังของเซลล์ว่างถูกซ่อนหรือไม่ด้วย JavaScript

ใช้คุณสมบัติ emptyCells เพื่อตั้งค่าหรือตรวจสอบว่าเซลล์ว่างในตารางจะแสดงขอบและพื้นหลังหรือไม่ ค่า show (แสดง), hide (ซ่อน)

ตัวอย่าง

<!DOCTYPE html>
<html>
  <head>
    <style>
      table, td {
        border:1px solid;
      }
    </style>
  </head>
  <body>
    <table id="myID" style="empty-cells:hide;">
      <tr>
        <td>One</td>
        <td>111</td>
      </tr>
      <tr>
        <td>Two</td>
        <td>222</td>
      </tr>
      <tr>
        <td>Three</td>
        <td></td>
      </tr>
    </table>
    <br>
    <button type="button" onclick="display()">Return</button>
    <script>
      function display() {
        document.write(document.getElementById("myID").style.emptyCells);
      }
    </script>
  </body>
</html>