您的位置:程序门 -> web 开发 -> javascript



已知一个对象,如何获取其下一级的对象?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


已知一个对象,如何获取其下一级的对象?[已结贴,结贴人:nonooo]
发表于:2007-01-19 17:08:15 楼主
<table   id= "mytable ">
    <tr>
        <td>
            <table   id= "firsthalf ">
            </table>
        </td>
            <div>
                <table   id= "secondhalf ">                
                </table>
            </div>
        <td>
        </td>
    </tr>
</table>


我已经通过
mytable   =   document.getelementbyid( "mytable ");
获取到了最外层表格mytable的引用了,我如何通过mytable获取到内层表格firsthalf和secondhalf的引用?
发表于:2007-01-19 17:27:441楼 得分:40
<body   onload=aa()>
<table   id= "mytable ">
    <tr>
        <td>
            <table   id= "firsthalf ">
1
            </table>
        </td>
            <div>
                <table   id= "secondhalf ">
2                
                </table>
            </div>
        <td>
        </td>
    </tr>
</table>
</body>
<script>
function   aa()
{
var   mytable   =   document.getelementbyid( "mytable ");
alert(mytable.childnodes[0].childnodes[0].childnodes[0].childnodes[0].id)
}
</script>
发表于:2007-01-19 17:33:192楼 得分:0
用children也行 <body   onload=aa()>
<table   id= "mytable ">
    <tr>
        <td>
            <table   id= "firsthalf ">
1
            </table>
        </td>
            <div>
                <table   id= "secondhalf ">
2                
                </table>
            </div>
        <td>
        </td>
    </tr>
</table>
</body>
<script>
function   aa()
{
var   mytable   =   document.getelementbyid( "mytable ");
alert(mytable.children[0].children[0].children[0].children[0].id)
}
</script>
发表于:2007-01-19 17:34:453楼 得分:0
用table的rows,cells也行
<body   onload=aa()>
<table   id= "mytable ">
    <tr>
        <td>
            <table   id= "firsthalf ">
1
            </table>
        </td>
            <div>
                <table   id= "secondhalf ">
2                
                </table>
            </div>
        <td>
        </td>
    </tr>
</table>
</body>
<script>
function   aa()
{
var   mytable   =   document.getelementbyid( "mytable ");
alert(mytable.rows[0].cells[0].childnodes[0].id)
}
</script>
发表于:2007-01-19 17:55:484楼 得分:0
好使~~谢谢!!!


快速检索

最新资讯
热门点击