为什么是七个孩子?container中的childnodes个数为什么不是3而是7?
<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<!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" xml:lang="zh-CN" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
<script type="text/javascript">
function countDiv(){
var obj_div = document.getElementById('container');
var cn =obj_div.childNodes.length
</script>
<body>
<div id="container">
<div id="1">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="9%" rowspan="2">
<div align="center">1</div>
</td>
<td width="30%" rowspan="2">
<div align="center"><span width="106" height="106" /></div>
</td>
<td width="25%"></td>
<td width="36%"> </td>
</tr>
<tr>
<td><span src="../My Documents/icon_digg.gif" width="13" height="8" title="上移" onclick="upmove('1');"/>
<img alt="为何是七个孩子?container中的childnodes个数为什么不是3而是7" src="../My Documents/icon_bury.gif" width="13" height="8" title="下移" onclick="downmove('1');"/>
<img src="del.gif" width="7" height="7" title="删除" onclick="delVideo('1');"/></td>
</tr>
</table>
</div>
<div id="2">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="9%" rowspan="2"><div align="center">2</div></td>
<td width="30%" rowspan="2"><div align="center"><span width="80" height="60" /></a></span></div></td>
<td width="25%"></td>
<td width="36%"> </td>
</tr>
<tr>
<td><span src="../My Documents/icon_digg.gif" width="13" height="8" title="上移" onclick="upmove('2');"/>
<img alt="为何是七个孩子?container中的childnodes个数为什么不是3而是7" src="../My Documents/icon_bury.gif" width="13" height="8" title="下移" onclick="downmove('2');"/>
<img src="del.gif" width="7" height="7" title="删除" onclick="delVideo('2');"/></td>
</tr>
</table>
</div>
<div id="3">
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="9%" rowspan="2"><div align="center">3</div></td>
<td width="30%" rowspan="2"><div align="center"><span width="152" height="114" /></div></td>
<td width="25%"></td>
<td width="36%"> </td>
</tr>
<tr>
<td><span src="../My Documents/icon_digg.gif" width="13" height="8" title="上移" onclick="upmove('3');" />
<img alt="为何是七个孩子?container中的childnodes个数为什么不是3而是7" src="../My Documents/icon_bury.gif" width="13" height="8" title="下移" onclick="downmove('3');"/>
<img src="del.gif" width="7" height="7" title="删除" onclick="delVideo('3');"/></td>
</tr>
</table>
</div>
</div>
<input value="显示" type="button" onclick="countDiv()" title="显示"/></button>
</body>
</html>
1 楼 7thbyte 2008-06-13 完全没有排版,很难阅读啊。。
初步认为是一些空格被当作了textNode