


Detailed explanation of example code for traversing cell content with js and jquery
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 is obtained by using the document object.
jQuery traverses the contents of td in tr in Table:
1. $("#trID td").text() gets a string, so the value of td in trID returns a string.
2. $("#trID").children gets all td under a trID, then traverses $("#trID").children and uses .eq(index).text() to get the td in Value;
<!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> <pid ="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> </p> <pid ="xiugai"style="display:none; background-color:#FFC; height:360px; width:260px"> ID:<label></label><br/> 姓名:<label></label><br/> 密码:<label></label><br/> <buttononclick="fanhui()">返回</button> </p> </body> </html>
The above is the detailed content of Detailed explanation of example code for traversing cell content with js and jquery. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

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

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:

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute
