jQuery gets td tag in table table
This article mainly brings you an article on jQuery to obtain the td tag in the table table (explanation with examples). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
First of all, let me introduce the problems I encountered
1. When a table contains
<tr> <td> @scene.ID </td> <td> @scene.SceneName </td> <td> @scene.QRUrl </td> <td> @scene.LocalUrl </td> <td> <!--如果有图片,展示图片,没有图片生成图片--> <!--判断localUrl(本地服务器路径)是否为空,如果为空,表示没有生成,如果不为空表示已经生成--> @if (!string.IsNullOrWhiteSpace(scene.LocalUrl)) { <!--图片不为空,展示图片地址--> <img src="@scene.LocalUrl" style="width:200px; height:100px"/> } else { <!--图片为空,生成图片--> <a sceneid="@scene.ID" href="#" rel="external nofollow" rel="external nofollow" onclick="build(this);">生成</a> } </td> </tr>
2. There is an onclick event here. All I have to do is click the "Generate" link and find the
First We click on this a tag to execute the click event in jQuery
function build(sender){ var jqSender = $(sender); + +} Here the js object is converted into a jquery object through $(), as follows The content is placed between two "+".
var sceneid = jqSender.attr('sceneid'); //attr can find the value of the object's attribute. Here we find the value of the sceneid attribute.
I need to get the td tag , first I should know which row it is in, which is the same as positioning. For example: There is a No. 1 Nanjing Road in Beijing, and there is a No. 1 Nanjing Road in Chengdu. You ask me where I am, and I tell you that I am at No. 1 Nanjing Road. Can you be sure whether I am in Beijing or Chengdu, so we should To locate, say we are at No. 1 Nanjing Road, Chengdu.
It is best to use eq() to get a certain row here. If the page code needs to be modified, this will be very troublesome. For example, if you want to remember where my house is, what you need to know is the street and house number. You only know that the first house on this street is my house. If someone else adds a new house here, it will not be the first house. (The analogy is a little inappropriate, but computers are so rigid).
So, 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> <td> <!--如果有图片,展示图片,没有图片生成图片--> <!--判断localUrl(本地服务器路径)是否为空,如果为空,表示没有生成,如果不为空表示已经生成--> @if (!string.IsNullOrWhiteSpace(scene.LocalUrl)) { <!--图片不为空,展示图片地址--> <img src="@scene.LocalUrl" style="width:200px; height:100px"/> } else { <!--图片为空,生成图片--> <a sceneid="@scene.ID" href="#" rel="external nofollow" rel="external nofollow" onclick="build(this);">生成</a> } </td> </tr>
Then you can find it in jQuery like this:
<script type="text/javascript"> function build(sender) { var jqSender = $(sender); var sceneid = jqSender.attr('sceneid'); //找到指定行类名为wxurl-col的td标签 $('tbody tr[sceneid=' + sceneid + '] td.wxurl-col') //找到指定行类名为localurl-col的td标签 $('tbody tr[sceneid=' + sceneid + '] td.localurl-col') //找到点击事件的a标签 jqSender } </script>
Detailed explanation of jQuery implementation to obtain the row number and column number of the mouse click position in the table
How to obtain the table in JavaScript The value of a certain column
Implementation code for using jQuery to obtain the row id and td value in the table_jquery
The above is the detailed content of jQuery gets td tag in table table. 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

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



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

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

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

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: <

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of "What is the clock behind the Douyin label", hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

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:

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
