Source: http://www.cnblogs.com/zhwl/p/3858682.html
The first case is that the width and height are written in the style sheet, like #div1{width:120px;}. In this case, the width can not be obtained by #div1.style.width, but by #div1.offsetwidth.
The second case is that the width and height are written in the middle of the line, such as style= "width:120px;", which can be obtained by the above 2 methods.
Summary, because Id.offsetwidth and id.offsetheight ignore the style of writing in the style sheet or in line, so we get the element width and height when the best use of these 2 attributes. Note If you do not write a property in a style within a row, you cannot get it through ID.STYLE.ATRR.
Today's front-end productions seldom write styles directly in style, they are written in the style table. If you want to get a style that does not correspond (like #div1.style.width corresponding to #div1.offsetwidth), you can only use the browser to get the style sheet properties, you may try to search "JS get style properties" and so on.
JS gets the actual width height of the HTML element