console
var box1 = document.getElementById('box1');
var btn = document.getElementById('btn');
btn.onclick = function(){
box1.style.width = '200px';
box1.style.height = '200px';
box1.style.backgroundColor = 'green';
}
var btn2 = document.getElementById('btn2');
btn2.onclick = function(){
console.log(box1.style.width);
console.log(box1.style.height);
console.log(box1.style.backgroundColor);
}
var btn3 = document.getElementById('btn3');
btn3.onclick = function(){
console.log(getStyle(box1,'width'));
}
function getStyle(obj, name){
return window.getComputedStyle ? getComputedStyle(obj,null)[name] : obj.currentStyle[name];
}
var box2 = document.getElementById('box2');
var btn4 = document.getElementById('btn4');
btn4.onclick = function(){
console.log(box1.clientWidth);
console.log(box1.offsetWidth);
var op = box2.offsetParent;
alert(box2.offsetLeft);
alert(box2.offsetTop);
}
<button id="btn">点击一下</button>
<button id="btn2">点击一下</button>
<button id="btn3">点击一下</button>
<button id="btn4">点击</button>
<div id="box1" style="position:relative">
<div id="box2" style="position:relative"></div>
</div>
#box1{
background: red;
width: 120px;
height: 120px;
margin-top: 20px;
padding: 10px;
border: 5px solid black;
}