Làm cách nào để thêm dữ liệu vào bảng bằng JavaScript?

The “insertRow()” method is utilized to add a new row at the beginning of the table. It creates a new element and inserts it into the table. It takes an index as a parameter that defines the location of the table where a row will be added. If “0” or no index will be passed in a method, this method adds the row at the start of the table.

Nếu bạn định thêm hàng vào cuối/cuối bảng, hãy chuyển chỉ mục “-1” làm đối số

cú pháp

Sử dụng cú pháp sau để thêm hàng trong bảng với sự trợ giúp của phương thức insertRow()

bảng. insertRow( index );

Ở đây, “chỉ mục” cho biết vị trí mà bạn muốn thêm một hàng mới, chẳng hạn như ở cuối bảng hoặc ở đầu bảng

ví dụ 1. Thêm một hàng ở trên cùng/bắt đầu của bảng

Here, we will create a table and a button in an HTML file using the HTML

and tags. The table contains three rows and three columns or cells:

Chủ đề