JQuery learning notes (4) -- train of thought for getting a column value in table in Jquery _ jquery-js tutorial

Source: Internet
Author: User
To obtain an ID value in a column, this problem does not exist if you use JS to pass the value. Because jquery plug-ins are used this time, including various pop-up boxes, the ugly pop-up box of JS is used to pass values with JS. Therefore, it takes you one night to solve a seemingly easy problem. In this task, you need to obtain an ID value in a column. This problem does not exist if you use the common method of passing JS values. However, all jquery plug-ins are used this time, including various pop-up boxes, if you use JS to pass values, you have to use the ugly pop-up box of JS. So, you know.

I found a lot of methods on the Internet, but I couldn't use them. Later I thought of the mouse event in jquery. I could get the values of the current row and column when I move the cursor over the table. The page is as follows:

The specific operation is to click the "delete" button and then call the jquery plug-in page. At this time, you need to obtain the "ID" of the corresponding line for the operation. My method is:

First, define a global variable for the number of rows and columns, and then obtain the number of rows and columns of the row when the mouse goes through the button, and pay the global variable:

The Code is as follows:


Var trNum;
Var tdNum;
$ (Function (){
// Define a mouse event
$ ('# Users td'). hover (
Function (){
// Obtain the row number of the table
TrNum = $ (this). parent (). parent (). find ('tr '). index ($ (this). parent () [0]) + 1;
// Obtain the column number of the table
TdNum = $ (this). parent (). find ('td '). index ($ (this) [0]) + 1;
}
);


Here, "users" is the ID of this table, and then the business is processed according to this ID, as shown below:

The Code is as follows:


01. // click "pop-up box" and select "OK" for Business Processing
$ ("# Dialog-confirm"). dialog ({
AutoOpen: false,
Resizable: false,
Height: 150,
Modal: true,
Buttons :{
"OK": function (){
Var au_id = $ ('# users '). find ('tr: eq ('+ (trNum) + ')'). find ('td: eq (0 )'). text (); // obtain the ID value of the first column
// Service Processing omitted
......
},
"Cancel": function (){
$ (This). dialog ("close ");
}
}}
);


Small Problems combine great wisdom. It is the truth I have always advocated to improve my learning ability and problem-solving ability by solving problems!
Related Article

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.