How to get the current row of table in jquery

青灯夜游
Release: 2022-04-22 12:16:25
Original
4946 people have browsed it

Method: 1. Use "$("tr").click(function(){})" to bind the click event to the table row element and set the processing function; 2. In the function, use " $(this).index() 1" just get the row number of the clicked element. The value obtained by index() starts counting from 0 and needs to be incremented by 1.

How to get the current row of table in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

jquery gets the current row of the table

Gets the current row of the table (table), you can bind it to the table element Set a click event, which element is clicked, which is the current element; then determine the number of rows of the element.

Implementation idea:

  • Use click() to bind the click event to the table row element tr, and set the event processing function (tr defines the row in the HTML table)

  • In the processing function, use index() to obtain the position of the clicked element and obtain the number of rows of the clicked element.

    Note: The element position obtained by index() is from If the count starts at 0, it needs to be added by 1.

Implementation code:

       
商品 价格
T恤 ¥100
牛仔褂 ¥250
牛仔库 ¥150

判断点击列是表格的第几列

Copy after login

How to get the current row of table in jquery

Description: The element position obtained by the

index() method is from 0 At the beginning, so if you want to get the accurate number of rows, you need to calculate it and add 1 to the obtained value.

[Recommended learning:jQuery video tutorial,web front-end video]

The above is the detailed content of How to get the current row of table in jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!