Use jquery in an HTML page to get data for all the cells of a table

Source: Internet
Author: User

First in IE under var mytable = document.getElementById ("MyTable"). rows[1].cells[2].innerhtml;
In this way IE the following return error; The value of the InnerHTML ; The discovery of data is because . InnerHTML and jquery conflicts

That's the only way to get the value of the unit in jquery.

1. Get the table first with a few rows of data and a few columns of data
var rows = document.getElementById ("playlisttable"). Rows.length;//Get the number of rows (including thead)
var colums = document.getElementById ("playlisttable"). Rows[0].cells.length;//Get the number of columns

2. Loop through the data for each cell

The Get method is var Tdvalue = $ ("#playlistTable tr:eq (" +i+ ") td:eq (0)"). html ();//Where i is a variable; in that way ""

The normal situation is var Tdvalue = $ ("#playlistTable tr:eq (0) td:eq (0)"). html ();

if (Rows > 1) {//Do not thead the first line)
for (var i = 1; i < rows; i++) {//per row
var payobj = new Object ();
PAYOBJ.O_NBR = O_NBR;
var Tdvalue = $ ("#playlistTable tr:eq (" +i+ ") td:eq (0)"). html ();
if (Tdvalue = = "POS Entry") {
Payobj.p_pay_typ = "3";
Payobj.p_pos = $ ("#playlistTable tr:eq (" +i+ ") Td:eq (5)"). html ();
PAYOBJ.P_NBR = $ ("#playlistTable tr:eq (" +i+ ") Td:eq (4)"). html ();
Payobj.p_hl_zh = $ ("#playlistTable tr:eq (" +i+ ") Td:eq (7)"). html ();
}

3. Other discoveries

is in the JS inside can also be used to encapsulate the data object way

(1)//initialize JSON array; This is an array of objects
var a = Json.parse ("{\" title\ ": \" \ ", \" Data\ ": []}");

(2) Initializing objects

var payobj = new Object ();
PAYOBJ.O_NBR = "123456789";

payobj.name = "Wu Shui shui";

(3) Adding an object to an array

A.data.add (payobj);

(4) Formatting data

Formatting data
var obj=json.stringify (a);

(5) Submit to the backstage

$.ajax ({
URL: "${applicationscope.rootpath}contract/savepayoffinforofall.action",
Type: "Post",
Data: {'param‘:obj},
DataType: "JSON",
Success:function (data) {
var obj = eval ("(" + Data + ")");
if (obj.success) {
Mini.unmask ();
alert (obj.message);

Location.reload ();
}
else {
Mini.unmask ();
alert (obj.message);
}
}
});

(6) Background parsing data

String param = request.getparameter ("param");
Jsonobject json=jsonobject.fromobject (param);
@SuppressWarnings ("Unchecked")
List<map<string,string>> Paylist=json.getjsonarray ("data");

The following can be a normal list of operation data

Use jquery in an HTML page to get data for all the cells of a table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.