js 判断某个对象是不是dom对象

<script type="text/javascript">
//首先要对HTMLElement进行类型检查,因为即使在支持HTMLElement的浏览器中,类型却是有差别的,在Chrome,Opera中HTMLElement的类型为function,此时就不能用它来判断了 var isDOM = ( typeof HTMLElement === 'object' ) ? function(obj){ return obj instanceof HTMLElement; } : function(obj){ return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string'; } </script>

 

posted @ 2016-07-11 13:27  wangmeihong  阅读(1805)  评论(0编辑  收藏  举报