table中,td里的元素取下一个td里的元素?
<tr>
<td>A</td>
<td>B</td>
</tr>
怎么根据A的id取到B??
nextSibling取不到。。。
------解决方案--------------------
<!DOCTYPE>
<html>
<head>
<title></title>
<script type='text/javascript'>
window.onload=function(){
var t1 = document.getElementById('t1');
a = t1.getElementsByTagName('td')[0];
b = a.nextElementSibling
------解决方案--------------------
a.nextSibling;
alert(b.innerHTML);
}
</script>
</head>
<body>
<table id='t1'>
<tbody>
<tr>
<td>A</td>
<td>B</td>
</tr>
<tbody>
</table>
</body>
</html>
------解决方案-------------------- window.onload=function(){
var t1 = document.getElementById('t1');
a = t1.getElementsByTagName('td')[0];
b = a.nextElementSibling
------解决方案-------------------- a.nextSibling;
alert(b.innerHTML);
}
你都这样写了,那第二个直接t1.getElementsByTagName('td')[1]不行吗 如果想用nextSibling 直接用var o = t1.childNodes(0).nextSibling ;