Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery determine which column to click on?

Shulou Source: shulou.com Published: 2022-05-31 18:40:39 10月02日 Update

Most people do not understand the knowledge points of this article "jquery how to judge which column to click on", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "jquery how to judge which column is clicked" article.

Method: 1, use "element .click (function () {})" to bind the click event to the element, and set the handler function; 2, in the function, use the "$(this). Index () + 1" statement to get the number of rows of the click element. The element positions obtained by index () are counted from 0 and need to be processed by adding 1.

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

Jquery determines which column is clicked.

Realize the idea:

Bind the click event to the element with click () and set the event handler

In the processing function, use index () to get the location of the clicked element and the number of rows of the clicked element

Note: the element positions obtained by index () are counted from 0 and need to be processed by adding 1.

Implementation code:

Tr:nth-of-type (even) {background-color: red;} tr:nth-of-type (odd) {background-color: pink } $(document) .ready (function () {$("tr") .click (function () { Console.log ("is the first of the table" + ($(this) .index () + 1) + "column") );}) Commodity price T-shirt ¥100 cowboy coat ¥250 jeans library ¥150

Determine which column of the table the click column is.

Description:

The element position obtained by the index () method starts at 0, so if you want to get the exact number of rows, you need to calculate and add 1 to the value.

The above is about the content of this article on "how to determine which column to click on by jquery". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.

Tags: Element content processing location function event article method cowboy knowledge article table T-shirt code value price commodity foundation most of which is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn macOS Xiaomi Microsoft