重新发一下,调整一下格式,再说明一下,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>

解决方案 »

  1.   

    再补充一下,alert起作用,但是提示undefined,应该提示tr就对了
      

  2.   

    onChange="alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName);"
    这一顿parentNode,指向哪去了?好乱呀
      

  3.   

    onChange="alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.tagName);" 
    提示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>
    这次应该清楚了吧?
      

  4.   

    建议如下:
    1、不要直接写在onChange里面建议这样写:
    onChange="show()"
    <script language="JavaScript">
    function  show(0
    {
        alert(this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.previousSibling.tagName); 
    }
    </script>
      

  5.   

    </tr>
    <tr bgcolor="#ffffcc">帅哥,这里不要换行就行了因为 W3C DOM 中空格或者换行被认为是一个文字节点
    所以你写的 previousSibling 指向的就是这个换行符
    所以你如果你有空格或者换行,必须这样子用
    this.previousSibling.previousSibling.tagName
    才可以,要不就别留空格或者换行
      

  6.   

    两个tr中间有个<!--明细科目列表-->也会有影响吗?
      

  7.   

    onclick="javascript:showbm(document.getElementById("bm1b2"),document.getElementById("plus1b2"));" 
    onclick="javascript:showbm(document.getElementById('bm1b2'),document.getElementById('plus1b2'));" 
    单双引号问题。
      

  8.   

    下面这样就没问题了,帅哥<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>
      

  9.   

    最后那个previousSibling去掉,问题所在
      

  10.   


     <a onclick="javascript:showbm(document.getElementById('bm1b2'),document.getElementById('plus1b2'));" style="text-decoration: none; color: rgb(0, 0, 0);" href="#">
      

  11.   

    这句没关系,我是从其他地方抄过来就抄的有了单双引号问题了,主要就是alert那句
      

  12.   

    原来在动态网页中previousSibling要输两次才可以
      

  13.   

    说了N遍了,你还是没明白
    因为 W3C DOM 中空格或者换行被认为是一个文字节点
    所以你写的 previousSibling 指向的就是</tr>
    <tr bgcolor="#ffffff">这两句之间的"换行符"
     
    所以你如果你有空格或者换行,必须这样子用 
    this.previousSibling.previousSibling.tagName 
    才可以,要不就别留空格或者换行
      

  14.   

    真晕,为什么在我机器上,就是alert出来的TR呢。我米发现任何错误啊<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <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>
      

  15.   

    </tr><tr bgcolor="#ffffff">
    我已经这样写了,还是不行,其实输几个previousSibling是不一定的,很难把握,有时候需要输2个,有时候要输3个,即使中间没有空格或换行,在动态网页中就是这样,我把从客户端页面上截下来的html代码直接用浏览器显示,只有这样,要输几个previousSibling才有章可循