• js


    1.

    <!DOCTYPE HTML>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style>
    div {padding: 40px 50px;}
    #div1 {background: red;}
    #div2 {background: green; zoom: 1;}
    #div3 {background: orange;}
    </style>
    <script>
    window.onload = function() {
    	
    	var oDiv3 = document.getElementById('div3');
    	
    	//parentNode : 父节点
    	//alert( oDiv3.parentNode.id );//body1
    	
    	/*
    		元素.offsetParent : 只读 属性 离当前元素最近的一个有定位属性的父节点
    			如果没有定位父级,默认是body
    			ie7以下,如果当前元素没有定位默认是body,如果有定位则是html
    			ie7以上,如果当前元素的某个父级触发了layout,那么offsetParent就会被指向到这个触发了layout特性的父节点上
    	*/
    	
    	//layout
    	
    	/*alert( document.getElementById('div2').currentStyle.hasLayout );*/
    	
    	alert( oDiv3.offsetParent.id );
    	
    	
    }
    </script>
    </head>
    
    <body id="body1">
    	<div id="div1">
        	<div id="div2">
            	<div id="div3"></div>
            </div>
        </div>
    </body>
    </html>
    

     3.

    	/*
    		元素.offsetLeft[Top] : 只读 属性 当前元素到定位父级的距离(偏移值)
    			到当前元素的offsetParent的距离
    			
    			如果没有定位父级
    				offsetParent -> body
    				offsetLeft -> html
    			
    			如果有定位父级
    				ie7以下:如果自己没有定位,那么offsetLeft[Top]是到body的距离
    					如果自己有定位,那么就是到定位父级的距离
    				其他:到定位父级的距离
    	*/
    
  • 相关阅读:
    c# 获取某个对象的[公有属性]的名称,类型,值
    iis10 HTTP 错误 500.19
    MVC 使用EF Code First数据迁移之添加字段
    emeditor 配置教程
    独立程序员如何赚钱致富
    win7/win8通过媒体流(DLNA技术)共享音乐照片和视频
    sails中文文档地址
    游戏碰撞的原理
    Android图片圆角效果
    Android 系统 root 破解原理分析 (续)
  • 原文地址:https://www.cnblogs.com/bravolove/p/5996538.html
Copyright © 2020-2023  润新知