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

ตั้งค่าให้เส้นขอบตารางรวมเป็นเส้นเดียวหรือไม่ด้วย JavaScript


หากต้องการตั้งค่าให้เส้นขอบตารางรวมเป็นเส้นเดียว ให้ใช้คุณสมบัติ borderCollapse และตั้งค่าเป็น collapse คุณสามารถลองรันโค้ดต่อไปนี้เพื่อตั้งค่าให้เส้นขอบตารางรวมเป็นเส้นเดียว −

ตัวอย่าง

<!DOCTYPE html> <html>    <body>       <table id="newTable" border="2">          <tr>             <th>EmpID</th>             <th>EmpName</th>             <th>EmpDept</th>          </tr>          <tr>             <td>001</td>             <td>Amit</td>             <td>IT</td>          </tr>          <tr>             <td>002</td>             <td>John</td>             <td>Finance</td>          </tr>          <tr>             <td>003</td>             <td>David</td>             <td>Marketing</td>          </tr>       </table>       <br>       <button onclick="display()">Click to collapse</button>       <script>          function display() {             document.getElementById("newTable").style.borderCollapse = "collapse";          }       </script>    </body> </html>