


How to traverse the contents of all cells in a Table using JS and jQuery_javascript skills
The example in this article describes the method of traversing the contents of all cells in the Table using JS and jQuery. Share it with everyone for your reference, the details are as follows:
Use JS to traverse the contents of all cells in the Table . You can use the following JS code to achieve this:
function GetInfoFromTable(tableid) { var tableInfo = ""; var tableObj = document.getElementById(tableid); for (var i = 0; i < tableObj.rows.length; i++) { //遍历Table的所有Row for (var j = 0; j < tableObj.rows[i].cells.length; j++) { //遍历Row中的每一列 tableInfo += tableObj.rows[i].cells[j].innerText; //获取Table中单元格的内容 tableInfo += " "; } tableInfo += "\n"; } return tableInfo; }
The parameter of this method is the id that uniquely identifies the Table, which can be obtained using the document object
jQuery traverses the contents of td in tr in Table:
1. $("#trID td").text() gets the value of td in trID and returns a string.
2. $("#trID").children gets all tds under a trID, and then traverses $("#trID").children and uses .eq(index).text() to get the value in td;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <htmlxmlns="http://www.w3.org/1999/xhtml"> <head> <metahttp-equiv="Content-Type"content="text/html; charset=gb2312"/> <title>无标题文档</title> <scriptlanguage="javascript"src="jquery-1.6.2.min.js"type="text/javascript"></script> <scriptlanguage="javascript"> $(document).ready(function() { $("#table a").each(function (){ this.onclick = function(){ var thisObj = this.parentNode.parentNode; var a = $(thisObj).children(); var arr = new Array(); var laber = $("#xiugai label"); for(var i=0;i<a.length;i++){ arr[arr.length] = a.eq(i).text(); } for(var i=0;i<laber.length;i++){ laber.eq(i).text(arr[i]); } $("#table").hide(); $("#xiugai").show(2000) } }); }); function fanhui(){ $("#table").show(2000); $("#xiugai").hide(2000); } </script> </head> <body> <divid ="table"> <tablewidth="470"border="0"cellspacing="0"cellpadding="0"> <trid="tr1"> <td>id</td> <td>名字</td> <td>密码</td> <td>操作</td> </tr> <trid="tr2"> <td>1</td> <td>张三</td> <td>12</td> <td><ahref="#">删除</a></td> </tr> <trid="tr3"> <td>2</td> <td>李四</td> <td>34</td> <td><ahref="#">删除</a></td> </tr> <trid="tr4"> <td>3</td> <td>王五</td> <td>56</td> <td><ahref="#">删除</a></td> </tr> <trid="tr5"> <td>4</td> <td>六子</td> <td>78</td> <td><ahref="#">删除</a></td> </tr> </table> </div> <divid ="xiugai"style="display:none; background-color:#FFC; height:360px; width:260px"> ID:<label></label><br/> 姓名:<label></label><br/> 密码:<label></label><br/> <buttononclick="fanhui()">返回</button> </div> </body> </html>
I hope this article will be helpful to everyone in JavaScript programming.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Is it frustrating to automatically remove leading zeros from Excel workbooks? When you enter a number into a cell, Excel often removes the leading zeros in front of the number. By default, it treats cell entries that lack explicit formatting as numeric values. Leading zeros are generally considered irrelevant in number formats and are therefore omitted. Additionally, leading zeros can cause problems in certain numerical operations. Therefore, zeros are automatically removed. This article will teach you how to retain leading zeros in Excel to ensure that the entered numeric data such as account numbers, zip codes, phone numbers, etc. are in the correct format. In Excel, how to allow numbers to have zeros in front of them? You can preserve leading zeros of numbers in an Excel workbook, there are several methods to choose from. You can set the cell by

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

WPS software is an indispensable helper for text and document processing. In practical applications, it is often necessary to operate in cells to process text and documents. There is a lot of knowledge about cells. Today, let me introduce the specific steps on how to divide a cell into two in WPS. 1. First, we open the WPS table that needs to be edited and select the cell document that needs to be divided into two cells. 2. Click to open "Column" in the data. 3. Then select "Fixed Width" in the pop-up window and click "Next". 4. In the pop-up window, click where you want to separate columns and press Enter to confirm. Draw inferences from one example. If you need to change it to 3, you can also change the number to 3. 5. Then click Finish. 6. There is another way

Java is a popular programming language with powerful file handling capabilities. In Java, traversing a folder and getting all file names is a common operation, which can help us quickly locate and process files in a specific directory. This article will introduce how to implement a method of traversing a folder and getting all file names in Java, and provide specific code examples. 1. Use the recursive method to traverse the folder. We can use the recursive method to traverse the folder. The recursive method is a way of calling itself, which can effectively traverse the folder.

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:
