重新发一下,调整一下格式,再说明一下,alert为什么不起作用?<tr>
<td bgcolor="#ccffcc">
<a onclick="javascript:showbm(document.getElementById("bm1b2"),document.getElementById("plus1b2"));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
<img id="plus1b2" style="border: medium none ;" src="../evidence/icon/M3.gif"/>
</a>
银行存款
<input type="hidden" value="58" name="acc_id1b2"/>
</td>
<td bgcolor="#ccffcc">
<input id="qcs1b2" type="text" value="0" size="18" name="qcs1b2"/>
</td>
</tr>
<tr bgcolor="#ffffcc">
<td colspan="2">
<table id="bm1b2" width="100%" cellspacing="0" cellpadding="0" bordercolor="#000000" border="1" style="border-collapse: collapse;">
<col width="200"/>
<col width="150"/>
<tbody>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
<td>
</td>
<td>
<input id="qcs1b2c2" type="text" onchange="javascript:alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);" value="0" size="18" name="qcs1b2c2"/>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
</tr>
<tr bgcolor="#ffffff">
</tr>
</tbody>
</table>
</td>
</tr>
<td bgcolor="#ccffcc">
<a onclick="javascript:showbm(document.getElementById("bm1b2"),document.getElementById("plus1b2"));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
<img id="plus1b2" style="border: medium none ;" src="../evidence/icon/M3.gif"/>
</a>
银行存款
<input type="hidden" value="58" name="acc_id1b2"/>
</td>
<td bgcolor="#ccffcc">
<input id="qcs1b2" type="text" value="0" size="18" name="qcs1b2"/>
</td>
</tr>
<tr bgcolor="#ffffcc">
<td colspan="2">
<table id="bm1b2" width="100%" cellspacing="0" cellpadding="0" bordercolor="#000000" border="1" style="border-collapse: collapse;">
<col width="200"/>
<col width="150"/>
<tbody>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
<td>
</td>
<td>
<input id="qcs1b2c2" type="text" onchange="javascript:alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);" value="0" size="18" name="qcs1b2c2"/>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
</tr>
<tr bgcolor="#ffffff">
</tr>
</tbody>
</table>
</td>
</tr>
这一顿parentNode,指向哪去了?好乱呀
提示tr,但是再取得当前节点的前一个兄弟节点的tagName,提示却是undefined,应该是tr就对了,
我再把这段重抄一遍
<tr>/*this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling*/
<td bgcolor="#ccffcc">
<a onclick="javascript:showbm(document.getElementById("bm1b2"),document.getElementById("plus1b2"));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
<img id="plus1b2" style="border: medium none ;" src="../evidence/icon/M3.gif"/>
</a>
银行存款
<input type="hidden" value="58" name="acc_id1b2"/>
</td>
<td bgcolor="#ccffcc">
<input id="qcs1b2" type="text" value="0" size="18" name="qcs1b2"/>
</td>
</tr>
<tr bgcolor="#ffffcc">/*this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.*/
<td colspan="2">
<table id="bm1b2" width="100%" cellspacing="0" cellpadding="0" bordercolor="#000000" border="1" style="border-collapse: collapse;">
<col width="200"/>
<col width="150"/>
<tbody>
<tr>
<td>
</td>
<td>
<input id="qcs1b2c2" type="text" onchange="javascript:alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);" value="0" size="18" name="qcs1b2c2"/>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
这次应该清楚了吧?
1、不要直接写在onChange里面建议这样写:
onChange="show()"
<script language="JavaScript">
function show(0
{
alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);
}
</script>
<tr bgcolor="#ffffcc">帅哥,这里不要换行就行了因为 W3C DOM 中空格或者换行被认为是一个文字节点
所以你写的 previousSibling 指向的就是这个换行符
所以你如果你有空格或者换行,必须这样子用
this.previousSibling.previousSibling.tagName
才可以,要不就别留空格或者换行
onclick="javascript:showbm(document.getElementById('bm1b2'),document.getElementById('plus1b2'));"
单双引号问题。
<td bgcolor="#ccffcc">
<a onclick="javascript:showbm(document.getElementById("bm1b2"),document.getElementById("plus1b2"));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
<img id="plus1b2" style="border: medium none ;" src="../evidence/icon/M3.gif"/>
</a>
银行存款
<input type="hidden" value="58" name="acc_id1b2"/>
</td>
<td bgcolor="#ccffcc">
<input id="qcs1b2" type="text" value="0" size="18" name="qcs1b2"/>
</td>
</tr>
<tr bgcolor="#ffffcc">
<td colspan="2">
<table id="bm1b2" width="100%" cellspacing="0" cellpadding="0" bordercolor="#000000" border="1" style="border-collapse: collapse;">
<col width="200"/>
<col width="150"/>
<tbody>
<tr>
<td>
</td>
<td>
</td>
</tr><tr bgcolor="#ffffff">
</tr>
<tr>
<td>
</td>
<td>
<input id="qcs1b2c2" type="text" onchange="javascript:alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);" value="0" size="18" name="qcs1b2c2"/>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
</tr>
<tr bgcolor="#ffffff">
</tr>
</tbody>
</table>
</td>
</tr>
<a onclick="javascript:showbm(document.getElementById('bm1b2'),document.getElementById('plus1b2'));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
因为 W3C DOM 中空格或者换行被认为是一个文字节点
所以你写的 previousSibling 指向的就是</tr>
<tr bgcolor="#ffffff">这两句之间的"换行符"
所以你如果你有空格或者换行,必须这样子用
this.previousSibling.previousSibling.tagName
才可以,要不就别留空格或者换行
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<table>
<tr>
<td bgcolor="#ccffcc">
<a onclick="javascript:showbm(document.getElementById('bm1b2'),document.getElementById('plus1b2'));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
<img id="plus1b2" style="border: medium none ;" src="../evidence/icon/M3.gif"/>
</a>
银行存款
<input type="hidden" value="58" name="acc_id1b2"/>
</td>
<td bgcolor="#ccffcc">
<input id="qcs1b2" type="text" value="0" size="18" name="qcs1b2"/>
</td>
</tr>
<tr bgcolor="#ffffcc">
<td colspan="2">
<table id="bm1b2" width="100%" cellspacing="0" cellpadding="0" bordercolor="#000000" border="1" style="border-collapse: collapse;">
<col width="200"/>
<col width="150"/>
<tbody>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
<td>
</td>
<td>
<input id="qcs1b2c2" type="text" onchange="javascript:alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);" value="0" size="18" name="qcs1b2c2"/>
</td>
</tr>
<tr bgcolor="#ffffff">
</tr>
<tr>
</tr>
<tr bgcolor="#ffffff">
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</BODY>
</HTML>
我已经这样写了,还是不行,其实输几个previousSibling是不一定的,很难把握,有时候需要输2个,有时候要输3个,即使中间没有空格或换行,在动态网页中就是这样,我把从客户端页面上截下来的html代码直接用浏览器显示,只有这样,要输几个previousSibling才有章可循