طريقة TableRow insertCell ()
مثال
أدخل خلية (خلايا) جديدة مع محتوى في بداية صف الجدول بالمعرف = "myRow":
var row = document.getElementById("myRow");
var x = row.insertCell(0);
x.innerHTML = "New cell";
التعريف والاستخدام
تقوم طريقة insertCell () بإدراج خلية في الصف الحالي.
تلميح: استخدم طريقة deleteCell () لحذف خلية في صف الجدول الحالي.
دعم المتصفح
Method | |||||
---|---|---|---|---|---|
insertCell() | Yes | Yes | Yes | Yes | Yes |
بناء الجملة
tablerowObject.insertCell(index)
قيمه المعامل
Value | Description |
---|---|
index | Required in Firefox and Opera, optional in IE, Chrome and Safari. A number (starts at 0) that specifies the position of the new cell in the current row. The value of 0 results in that the new cell will be inserted at the first position. The value of -1 can also be used; which results in that the new cell will be inserted at the last position. If this parameter is omitted, insertCell() inserts the new cell at the last position in IE and at the first position in Chrome and Safari. This parameter is required in Firefox and Opera, but optional in Internet Explorer, Chrome and Safari. |
تفاصيل تقنية
قيمة الإرجاع: | عنصر الخلية المدرج |
---|
مزيد من الأمثلة
مثال
أدخل خلية (خلايا) جديدة مع محتوى في نهاية صف الجدول بالمعرف = "myRow":
var row = document.getElementById("myRow");
var x = row.insertCell(-1);
x.innerHTML = "New cell";
مثال
أدخل خلية (خلايا) جديدة مع محتوى في موضع الفهرس 2 لصف الجدول بالمعرف = "myRow":
var row = document.getElementById("myRow");
var x = row.insertCell(2);
x.innerHTML = "New cell";
مثال
أدخل خلية (خلايا) جديدة في بداية صف الجدول الأول. تقوم مجموعة صفوف الجدول (.rows [0]) بإرجاع مجموعة من كافة عناصر <tr> في الجدول بالمعرف "myTable". يحدد الرقم [0] العنصر المراد استرداده ، في هذا المثال ، صف الجدول الأول. ثم نستخدم insertcell () لإدراج خلية (خلايا) جديدة في موضع الفهرس -1:
var firstRow = document.getElementById("myTable").rows[0];
var x = firstRow.insertCell(-1);
x.innerHTML = "New cell";
مثال
احذف الخلية (الخلايا) الأولى من صف جدول بالمعرف = "myRow":
var row = document.getElementById("myRow");
row.deleteCell(0);
مثال
قم بإدراج صف (صفوف) جديدة في بداية الجدول. تُدرج طريقة insertRow () صفًا جديدًا في الفهرس المحدد في جدول ، في هذا المثال ، الموضع الأول (البداية) من الجدول بالمعرف = "myTable". ثم نستخدم طريقة insertCell () لإضافة خلايا في الصف الجديد.
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";
❮ كائن TableRow