nextElementSibling 和 nextSibling 的区别
nextElementSibling 和 nextSibling 都是返回当前结点的下一个兄弟结点,但nextSibling 返回的兄弟结点包括了你js 源代码中的回车,换行,空格,文本等,而nextElementSibling 只返回当前元素结点之后的、不包括上述文本结点的兄弟结点。
<body>
<form action="" method="get">
<table align="center" border="2" >
<tr bgcolor="red">
<td colspan="2" align="center" >用户注册</td>
</tr>
<tr>
<td >用户名</td>
<td><input type="text" name="userName" id="firInput" class="intext">
<font style="color:red" id="oneFont" class="infont">*</font></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password" id="secInput" class="intext" >
<font style="color:red" id="twoFont" class="infont">*</font>
</td>
</tr>
<tr>
<td>确认密码</td>
<td><input type="password" name="twicePassword" id="thiInput" class="intext">
<font style="color:red" id="threeFont" class="infont">*</font></td>
</tr>
<tr>
<td>电话</td>
<td><input type="text" name="tel" id="fouInput" class="intext"><font style="color:red" id="fourFont" class="infont">*</font></td>
</tr>
<tr>
<td>邮箱</td>
<td><input type="text" name="email" id="fivInput" class="intext" >
<font style="color:red" id="fiveFont" class="infont">*</font></td>
</tr>
<tr>
<td><input type="button" value="注册"></td>
<td><input type="reset"></td>
</tr>
</table>
</form>
</body>
上面的 firInput 标签的 nextSibling 为一个换行 #test标签 而 nextElementSibling 为下面的 id 为 oneFont 的标签 dom 对象。 如下图: