search
HomeWeb Front-endJS TutorialDOM Basics Tutorial: Using DOM to Control Forms_Basic Knowledge

I won’t talk about the css control of the table for now. First, let’s share the commonly used DOM of the table

The commonly used methods for table addition operations are insertRow() and insertCell() methods.

row is calculated from zero, for example:

Copy code The code is as follows:
var oTr = document.getElementById("member").insertRow(2 )

means adding a new line to the second line.

Copy code The code is as follows:

var aText = new Array();
aText[0] = document.createTextNode("fresheggs");
aText[1] = document.createTextNode("W610");
aText[2] = document.createTextNode("Nov 5th");
aText[3] = document.createTextNode("Scorpio");
aText[4] = document.createTextNode("1038818");
for(var i=0;i var oTd = oTr.insertCell(i);
oTd.appendChild(aText[i]);
}

The variable oTr is to insert a new row into the table, then use insertCell to insert new data for this row, use createTextNode to create a new text node, and give it to oTd in appendChild, oTd is the new cell. ​

1. Insert a row (dynamically add a table)

Copy code The code is as follows:



   
   
       
       
       
       
       
   
   
       
       
       
       
       
   
   
       
       
       
       
       
   
   
       
       
       
       
       
   
Member List
Name Class Birthday Constellation Mobile
isaac W13 Jun 24th Cancer 1118159
girlwing W210 Sep 16th Virgo 1307994
tastestory W15 Nov 29th Sagittarius 1095245

2.修改表格的内容

当表格建立后,可以直接使用HtmlDom对表格进行操作,相比document.getElementById(),document.getElementsByTagName()操作更为方便。
oTable.rows[i].cell[j]
以上通过rows、cells两个属性轻松访问到表格特定的内容第i行和第j列(都是从0开始计数),获得单元格对象后就可以使用innerHTML属性修改翔宇的内容了。
例如修改4行5列的内容为good
则可以使用以下代码

复制代码 代码如下:

var oTable = document.getElementById("table1");
oTable.rows[4].cells[5].innerHTML = "good";

3.删除表格内容

表格既然有添加、修改、就有删除功能。
表格中删除行使用deleteRow(i)方法,其中i为行号。
表格中删除列使用tr的deleteCell(j)方法。

如下代码表示删除表格的第二行及原来表格第三行的第二列

复制代码 代码如下:
var oTable = document.getElementById("table1"); oTable.deleteRow[2]; oTable.rows[2].deleteCell[3];

The following code represents the deletion of the second row of the table and the second column of the third row of the original table. Considering that dynamic deletion does not affect the overall HTML framework, or when the table has a lot of content, dynamic deletion and addition can be used

Copy code The code is as follows:





                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
Member List
Class




Delete column





Copy code


The code is as follows:

function deleteColumn(oTable, iNum) {
                                               // Customize the column deletion function, that is, delete the corresponding cells in each row
for (var i = 0; i oTable.rows[i].deleteCell(iNum);
            }
               window.onload = function() {
              var oTable = document.getElementById("table1");
                   deleteColumn(oTable, 2);
            }

For deleting table columns, there is no directly callable method in the DOM. You need to write the deleteColumn() method yourself. This method accepts two parameters, one parameter is the table object, and the other parameter is the column you want to delete. Number. The writing method is very simple. Using the deleteCell() method, each row executes the corresponding method of deleting cells.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
css怎么去掉表格重复的边框css怎么去掉表格重复的边框Sep 29, 2021 pm 06:05 PM

在css中,可以使用border-collapse属性来去掉表格中重复的边框,该属性可以设置表格边框是折叠为单一边框还是分开的,只需要将值设置为collapse即可把重叠的边框合并在一起,成为一个边框,实现单线边框的效果。

表格有一条虚线外打印不到怎么办表格有一条虚线外打印不到怎么办Mar 28, 2023 am 11:38 AM

表格有一条虚线外打印不到的解决办法:1、打开excel文件,在打开的页面中点击“打印”;2、在预览页找到“无缩放”,选择调整为一页;3、选择打印机打印文档即可。

Vue文档中的表格勾选和全选函数操作方法Vue文档中的表格勾选和全选函数操作方法Jun 20, 2023 pm 10:33 PM

Vue是一种流行的JavaScript框架,它可以让开发人员轻松地构建交互式、响应式的Web界面。Vue框架提供了一系列的组件和指令,用于构建常见的页面元素,如表格、表单、菜单等。在这篇文章中,我们将探讨Vue文档中的表格勾选和全选函数操作方法。在Vue中,我们可以使用v-model指令将表单元素与Vue实例中的数据进行双向绑定。这使得我们可以轻松地收集用户

使用JavaScript实现表格数据的分页显示使用JavaScript实现表格数据的分页显示Jun 16, 2023 am 10:00 AM

随着数据的不断增长,表格显示变得更加困难。大多数情况下,表格中的数据量过大,导致表格在加载时变得缓慢,而且用户需要不断地浏览页面才能找到自己想要的数据。本文将介绍如何使用JavaScript实现表格数据的分页显示,让用户更容易找到自己想要的数据。一、动态创建表格为了使分页功能更加可控,需要动态创建表格。在HTML页面中,添加一个类似于下面的table元素。

Vue3获取DOM节点的方式有哪些Vue3获取DOM节点的方式有哪些May 11, 2023 pm 04:55 PM

1.原生js获取DOM节点:document.querySelector(选择器)document.getElementById(id选择器)document.getElementsByClassName(class选择器)....2.vue2中获取当前组件的实例对象:因为每个vue的组件实例上,都包含一个$refs对象,里面存储着对应的DOM元素或组件的引用。所以在默认情况下,组件的$refs指向一个空对象。可以先在组件上加上ref="名字",然后通过this.$refs.

wps表格如何按成绩高低排序wps表格如何按成绩高低排序Jun 21, 2023 am 09:30 AM

wps表格按成绩高低排序的方法:1、打开wps表格,点击菜单栏中的“开始”按钮;2、点击工具栏中的“排序”选项;3、在下拉菜单中点击“降序”选项;4、在“给出排序依据”下点击“扩展选定区域”,然后点击“排序”按钮即可按成绩高低排序。

在Excel表格中输入身份证号码为什么会变在Excel表格中输入身份证号码为什么会变Mar 10, 2023 am 11:14 AM

原因:身份证号属于数字串,若直接输入,Excel就会认为它是一个数值型数据;而当数据的位数超过11位后,常规格式下的Excel就会将其记为科学记数法,当位数超过15位后,Excel则只将其精确至15位,后面位数的数值就全为0。解决方法:1、点击身份证号所在的单元格;2、在单元格上点击鼠标右键,选择“设置单元格式”;3、点击“数字”选项卡,从分类列表里选中“文本”,点击“确定”。

使用JavaScript实现表格数据的在线编辑使用JavaScript实现表格数据的在线编辑Jun 15, 2023 pm 08:53 PM

在现代Web应用程序中,表格是一个常见的UI组件,用于展示和编辑数据。在某些情况下,用户可能需要在表格中直接进行编辑以便快速修改数据,而不必转到其他页面或使用外部工具进行修改。因此,实现在线表格编辑功能非常有用。在本文中,我将介绍如何使用JavaScript和一些开源库实现表格数据的在线编辑。1.HTML表格创建在开始使用JavaScript之前,请先创建

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function