编辑您的代码:提交代码

x
 
1
 
2
 
3
<html>
4
<head>
5
<script type="text/javascript">
6
function alertTd1()
7
  {
8
  alert(document.getElementById('td1').cellIndex);
9
  }
10
function alertTd2()
11
  {
12
  alert(document.getElementById('td2').cellIndex);
13
  }
14
</script>
15
</head>
16
<body>
17
18
<table border="1">
19
<tr>
20
<th>Firstname</th>
21
<th>Lastname</th>
22
</tr>
23
<tr>
24
<td id="td1">Peter</td>
25
<td id="td2">Griffin</td>
26
</tr>
27
</table>
28
<br />
29
<input type="button" onclick="alertTd1()" value="Alert cell index of 'Peter'" />
30
<br />
31
<input type="button" onclick="alertTd2()" value="Alert cell index of 'Griffin'" />
32
33
</body>
34
</html>
35
            

查看结果:

请在上面的文本框中编辑您的代码,然后单击提交按钮测试结果。w3c0.com

W3c0.com 提供的内容仅用于培训。我们不保证内容的正确性。通过使用本站内容随之而来的风险与本站无关。W3c0 简体中文版的所有内容仅供测试,对任何法律问题及风险不承担任何责任。 当使用本站时,代表您已接受了本站的使用条款和隐私条款。版权所有,保留一切权利。 鲁ICP备15022115号