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