js parentElement

<a href="http://sighttp.qq.com/cgi-bin/check?sigkey=a495e8ecdb9706da396929cf00ab6994683579aeb480e95867f7b027880b6b257ff6c38e3045a766df65e31bee05acefa20b053ae86d798501cb768fb02c84e8"; target=_blank; onclick="var tempSrc='http://sighttp.qq.com/wpa.js?rantime='+Math.random()+'&sigkey=a495e8ecdb9706da396929cf00ab6994683579aeb480e95867f7b027880b6b257ff6c38e3045a766df65e31bee05acefa20b053ae86d798501cb768fb02c84e8';var oldscript=document.getElementById('testJs');var newscript=document.createElement('script');newscript.setAttribute('type','text/javascript'); newscript.setAttribute('id', 'testJs');newscript.setAttribute('src',tempSrc);if(oldscript == null){document.body.appendChild(newscript);}else{oldscript.parentNode.replaceChild(newscript, oldscript);}return false;"><img border="0" SRC='http://wpslogo.qq.com/qq_online.gif'  alt="点击这里给我发消息"></a> &nbsp;&nbsp;(点击及可直接咨询)


<html>
<head> </head>
<body>
<form       name= "a ">      
<table   name= "b ">      
<tr   name= "c "   >      
                                <td   name= "d "   >      
                                            <select     name= "e "     onchange= "xx(this.parentElement.parentElement.parentElement.name) ">
    <option   > 1 </option>
    <option   > 2 </option>
    <option   > 3 </option>
    <option   > 4 </option>

    </select>
                                </td>    
<td> &nbsp; </td>
                                 
                    </tr>      
    <tr> &nbsp; </tr>
            </table>      
    </form>  
  </body>
  <script   language= "javascript ">
  function   xx(a)
  {
      alert(a);
  }
  </script>
</html>
//输出undefined   为什么了?   不是应该输出b么?


改成 this.parentElement.parentElement.parentElement.parentElement.name    正确输出
其实代码应该这样理解
<table>
<tbody>
<tr>
<td>
</td>
</tr>
有如:
   <SCRIPT language="javascript">
         function showHide(obj){
          var oStyle = obj.parentElement.parentElement.parentElement.rows[1].style;
         // obj.parentElement.parentElement.parentElement.rows[1].这里获取的是TABLE 第二行 id为sub的单元行
          oStyle.display == "none" ? oStyle.display = "block" : oStyle.display = "none";
         }
   </SCRIPT>

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 </HEAD>
 <BODY bgColor="#9aadcd" leftMargin="0" topMargin="0" >
  <br>
<asp:Repeater ID="LeftMenu" runat="server" OnItemDataBound="LeftMenu_ItemDataBound" >
  <ItemTemplate>
        <TABLE cellSpacing="0" cellPadding="0" width="159" align="center" border="0" >
          <TR >
           <TD width="23"><IMG height="25" src="images/Menu/box_topleft.gif" width="23"></TD>
           <TD class="ttl"
            onclick="JavaScript:showHide(this);" width="129" background="images/Menu/box_topbg.gif"><%# Eval("M_CName")%></TD>
           <TD width="7"><IMG height="25" src="images/Menu/box_topright.gif" width="7"></TD>
          </TR>
          <TR style="DISPLAY: none" id="sub">
           <TD background='images/Menu/box_bg.gif' colSpan='3'>
            

             <TABLE width='100%'>
                 <TBODY>
                 <asp:Repeater ID="LeftMenu_Sub" Runat="server" >
                 <ItemTemplate>
               <TR>
               <TD><IMG height='7' hspace='5' src='images/Menu/arrow.gif' width='5' align='absMiddle'>
                <asp:HyperLink ID ="Hyperlink1" Runat ="server" Target ="mainFrame" NavigateUrl='<%# Eval("M_Directory")%>'>
                 <%# Eval("M_CName")%>
                </asp:HyperLink>
               </TD>
              </TR>
              </ItemTemplate>
              </asp:Repeater>
                          </TBODY>
                         </TABLE>

                    </TD>
               </TR>
            <TR>
            <TD colSpan="3"><IMG height='10' src='images/Menu/box_bottom.gif' width='159'></TD>
            </TR>
         </TABLE>
        </ItemTemplate>
</asp:Repeater>  
 </BODY>
</html>

posted @ 2009-02-13 00:25  hemingchen  阅读(6019)  评论(0编辑  收藏  举报