例如:
<BODY>
<div style="border: 1px solid black;position:absolute;">
<form>
<input type="checkbox" id="cc">
</form>
</div>
這個例子中,“cc”元素的offsetParent是div,如果去掉div的position屬性,那麼cc的offsetParent就會變爲body。而parentElement一直都爲form。
與此相關的還有offsetLeft和offsetTop兩種屬性,他們分別表示的是元素與offsetElement相對應的左側和頂部距離。
學習原生JS dom操作遇到的問題,記錄一下,轉自http://blog.csdn.net/zj_2009/article/details/2087291