源代码:
下载代码
点击运行
<!DOCTYPE html> <html> <head> <style> table,th { border:1px solid black; } </style> </head> <body> <p>点击每个 th 元素,弹出提示框显示它们的索引位置:</p> <table> <tr> <th onclick="myFunction(this)">点击显示 cellIndex</th> <th onclick="myFunction(this)">点击显示 cellIndex</th> <th onclick="myFunction(this)">点击显示 cellIndex</th> <th onclick="myFunction(this)">点击显示 cellIndex</th> </tr> </table> <script> function myFunction(x) { alert("单元格索引是: " + x.cellIndex); } </script> </body> </html>
运行结果: