الجدول deleteRow () الطريقة
مثال
احذف الصف الأول من الجدول:
document.getElementById("myTable").deleteRow(0);
التعريف والاستخدام
طريقة deleteRow () تزيل الصف في الفهرس المحدد من الجدول.
تلميح: استخدم insertRow () لإنشاء وإدراج صف جديد.
دعم المتصفح
Method | |||||
---|---|---|---|---|---|
deleteRow() | Yes | Yes | Yes | Yes | Yes |
بناء الجملة
tableObject.deleteRow(index)
قيمه المعامل
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. An integer that specifies the position of the row to delete (starts at 0). The value of 0 results in that the first row will be deleted. The value of -1 can also be used; which result in that the last row will be deleted. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. If this parameter is omitted, deleteRow() removes the last row in IE and the first row in Chrome and Safari. |
تفاصيل تقنية
قيمة الإرجاع: | لا قيمة مردودة |
---|
مزيد من الأمثلة
مثال
احذف الصف الذي تضغط عليه:
function deleteRow(r) {
var i = r.parentNode.parentNode.rowIndex;
document.getElementById("myTable").deleteRow(i);
}
مثال
إنشاء وحذف الصف (الصفوف):
function myCreateFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = "NEW CELL1";
cell2.innerHTML = "NEW CELL2";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteRow(0);
}
الصفحات ذات الصلة
مرجع HTML: علامة <tr> HTML
❮ كائن الجدول