JQuery obtains the td tag and jquerytabletd tag in the table.

Source: Internet
Author: User

JQuery obtains the td tag and jquerytabletd tag in the table.

First, let me introduce my problems.

1. When a table contains a <tr> label and a <td> label, it can be considered as follows:

<Tr> <td> @ scene. ID </td> <td> @ scene. sceneName </td> <td> @ scene. QRUrl </td> <td> @ scene. localUrl </td> <! -- If there is an image, the image is displayed, and no image is generated --> <! -- Determines whether the localUrl (local server path) is null. if it is null, it indicates that it is not generated. if it is not null, it indicates that it has been generated --> @ if (! String. IsNullOrWhiteSpace (scene. LocalUrl) {<! -- The image is not empty. The image display address is --> } else {<! -- The image is empty and the image is generated --> <a sceneid = "@ scene. ID "href =" # "onclick =" build (this); "> Generate </a >}</td> </tr>
View Code

2. Here is an onclick event. All I need to do is click the "generate" link and find the <td> tag of QRUrl AND THE <td> tag of LocalUrl.

First, click the tag and execute the Click Event in jQuery.

Function build (sender) {var jqSender =$ (sender); ++} Here, the js object is converted into a jquery object through $ (), and the following content is placed between two "+.

Var sceneid = jqSender. attr ('sceneid'); // attr can find the attribute value of the object. Here we find the value of sceneid.

 

I need to get the td tag. First, I should know which line it is in, which is the same as positioning. For example, there is a No. 1 Nanjing Road in Beijing and a No. 1 Nanjing Road in Chengdu. If you ask where I am, I will tell you that I am at No. 1 Nanjing Road, are you sure you are in Beijing or Chengdu, so we should locate and say that we are at No. 1 Nanjing Road in Chengdu.

It is recommended that you use eq () to obtain a line. If the Page code needs to be modified, this will be very troublesome. For example, if you want to remember where my house is, you need to know the street and house number. You only know that the first house in this street is my house. If someone else adds a new house here, that's not the first one (the analogy is a bit inappropriate, but the computer is so rigid ).

Therefore, we set an id for this tr and a class for QRUrl and LocalUrl. The Code is as follows:

<Tr sceneid = "@ scene. ID "> <td> @ scene. ID </td> <td> @ scene. sceneName </td> <td class = "wxurl-col"> @ scene. QRUrl </td> <td class = "localurl-col"> @ scene. localUrl </td> <! -- If there is an image, the image is displayed, and no image is generated --> <! -- Determines whether the localUrl (local server path) is null. if it is null, it indicates that it is not generated. if it is not null, it indicates that it has been generated --> @ if (! String. IsNullOrWhiteSpace (scene. LocalUrl) {<! -- The image is not empty. The image display address is --> } else {<! -- The image is empty and the image is generated --> <a sceneid = "@ scene. ID "href =" # "onclick =" build (this); "> Generate </a >}</td> </tr>
View Code

In jQuery, you can find it like this:

<Script type = "text/javascript"> function build (sender) {var jqSender =$ (sender); var sceneid = jqSender. attr ('sceneid'); // find the td tag of the specified row class named wxurl-col $ ('tbody tr [sceneid = '+ sceneid +'] td. wxurl-col ') // find the td tag of the specified row class named localurl-col $ ('tbody tr [sceneid =' + sceneid + '] td. localurl-col ') // click the event's a tag jqSender} </script>
View Code

The td tag is only found and is not used.

The method is as follows: add "coordinates" to the element. Why are there multiple lines of IDs and class names respectively? to be unique, only id is added. When the row is determined, the column can be either id or class. We recommend that you use class to facilitate css management.

 

Note: This article is for reference only. It also has many flaws. The most important thing is not code, but logic.

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.