


A table called tb has n rows and m columns, and there are m tds in each row. Now I click on a grid with an ID called stid. Can I find out which column and row it is? _html/css_WEB-ITnose
A table called tb has n rows and m columns, and there are m TDs in each row. Now I click on a TD grid with an ID called stid. Can I find out which column and row it is? Or can we find the header of the row where stid is located (the content of the first td) and the column header of the column? ?
Reply to discussion (solution)
I tried using S('#stid').coloumn.header but it didn’t work
In each td Adding a hidden field should solve the problem, but I think the method is not very good. I wonder if there is anything ready-made in js.
There seems to be no ready-made method to retrieve it. You can give td an identifier when typing the table to retrieve it.
Yes, $("#stid").parent().index(), This is the index value of the row where the td with the ID name stid is located. You can get the row number.
Similarly, $("#stid").index() can get the index value of the td column, so you can get the row number. Column
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title></title> <style type="text/css"> td { height: 30px; width: 50px; text-align: center; border: 1px solid #333333; } </style></head><body> <div> <table id="tb"> <tr> <td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4 </td> <td> 5 </td> <td> 6 </td> <td> 7 </td> </tr> <tr> <td> 8 </td> <td> 9 </td> <td> 10 </td> <td> 11 </td> <td> 12 </td> <td> 13 </td> <td> 14 </td> </tr> <tr> <td> 15 </td> <td> 16 </td> <td> 17 </td> <td> 18 </td> <td> 19 </td> <td> 20 </td> <td> 21 </td> </tr> <tr> <td> 22 </td> <td> 23 </td> <td> 24 </td> <td> 25 </td> <td> 26 </td> <td> 27 </td> <td> 28 </td> </tr> <tr> <td> 29 </td> <td> 30 </td> <td> 31 </td> <td> 32 </td> <td> 33 </td> <td> 34 </td> <td> 35 </td> </tr> <tr> <td> 36 </td> <td> 37 </td> <td> 38 </td> <td> 39 </td> <td> 40 </td> <td> 41 </td> <td> 42 </td> </tr> </table> </div></body></html><script type="text/javascript"> var Table = document.getElementById("tb"); for (var i = 0; i < Table.rows.length; i++) { for (var j = 0; j < Table.rows[i].cells.length; j++) { Table.rows[i].cells[j].onclick = function () { var Table = document.getElementById("tb"); for (var i = 0; i < Table.rows.length; i++) { for (var j = 0; j < Table.rows[i].cells.length; j++) { if (this.innerText == Table.rows[i].cells[j].innerText) { alert(" 该TD的值为:" + this.innerText + " 行数为:" + i + " 列数为" + j + " 第一行的值为:" + Table.rows[i].cells[0].innerText); } } } } } }</script>
Hope it can help the poster, pure JS code
JavaScript code?123456789101112131415161718192021222324252627282930313233343536373839 40414243445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990... Looped List
What browser are you using? I have no problem using IE8/Google.
360
Wrong, 360 is no problem, Firefox is undefined, frustrating, so incompatible
<script type="text/javascript"> var bl = true; if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) { bl = false; } var Table = document.getElementById("tb"); for (var i = 0; i < Table.rows.length; i++) { for (var j = 0; j < Table.rows[i].cells.length; j++) { Table.rows[i].cells[j].onclick = function () { var Table = document.getElementById("tb"); for (var i = 0; i < Table.rows.length; i++) { for (var j = 0; j < Table.rows[i].cells.length; j++) { if (bl) { if (this.innerText == Table.rows[i].cells[j].innerText) { alert(" 该TD的值为:" + this.innerText + " 行数为:" + i + " 列数为" + j + " 第一行的值为:" + Table.rows[i].cells[0].innerText); } } else { var CText = innerText(this); var TableText = innerText(Table.rows[i].cells[j]); if (CText == TableText) { alert(" 该TD的值为:" + CText + " 行数为:" + i + " 列数为" + j + " 第一行的值为:" + innerText(Table.rows[i].cells[0])); } } } } } } } function innerText(node) {//返回的是数组类型 var innerTextArr = []; var root = node; var getChild = function (node) { var childs = node.childNodes; for (var i = 0; i < childs.length; i++) if (childs[i].nodeType == 3) innerTextArr.push(childs[i].nodeValue); else if (childs[i].nodeType == 1) { getChild(childs[i]); } } getChild(root); return innerTextArr[0].replace("\n", "").replace(/[ ]/g, "").replace("\n", ""); }</script>
Now that the compatibility is working with IE8/Firefox/Google, you can try again

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.
