js :parentNode,firstChild,parentNode,nextSibling;

来源:互联网 发布:重庆简米网络培训骗局 编辑:程序博客网 时间:2024/05/21 17:21
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">  
<html>  
    <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
        <title>Untitled Document</title>  
        <script language="JavaScript">  
             function test1() {
                 var node = document.getElementById("imgid2");  
                 var pimg = node.parentNode.firstChild;
                 var inpu = node.parentNode.nextSibling;
                 alert(pimg.value);
                 alert(inpu.value);
             }
        </script>  
    </head>  
    <body>  
    <div>
        <a id ="aid">
            <img id ="imgid" value="img1" />
            <img id ="imgid2" value="img2" />
        </a>
        <input type="text" value="input"/>
    </div>
        <input type="button" value="GOGO" onClick="test1();" />  
    </body>  
</html>