Click the table to obtain the table row or column index. The table obtains the column index.

Source: Internet
Author: User

Click the table to obtain the table row or column index. The table obtains the column index.

See ASP. net mvc View:

 

This section of html will generate a table.

Now we need to implement this. When you click a table, you can obtain the index of the row you click or the index of the column in the row.

Row index:

 

$ ('Table tr'). click (function () {var idx = $ (this). index (); alert (idx) ;}); Source Code



Column index:

 

$ ("Table tr td "). on ("click", function () {var idx = $ (this ). index (); alert (idx) ;}); Source Code



Demo:

 

The following content is added at, January 7:
You can also use the following jQuery code to obtain it. It is only for reference:

 

$ ('Table tr '). on ("click", 'td ', function () {var tdidx = $ (this ). index (); var tridx = $ (this ). closest ('tr '). index () ;}); $ ("table tr td "). on ("click", function () {var tdidx = $ (this ). index (); var tridx = $ (this ). closest ('tr '). index () ;}); Source Code

 

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.