<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试</title>
</head>
<body>
    <div style="width:100px; height: 100px; position: relative;">
        <div id="div1" style="width:50px; height: 50px; position: absolute; top: 20px; left: 20px;"></div>
    </div>
    <input type="button" value="按钮" id="btn1">
    <input type="text" id="tex1">
    <script>
        window.onload=function(){
            var oDiv=document.getElementById('div1');
            alert(oDiv.offsetParent.tagName);//弹出用于定位的父级.tagName父级名称
        }
    </script>
</body>
</html>

posted on 2016-01-18 16:21  茶白  阅读(357)  评论(0编辑  收藏  举报