ownerDocument表示当前的document对象html
var childElem = document.getElementById('testid'); if(childElem.ownerDocument()==document) { alert('ownerDocument is document dom object'); }
2.documentElement 表示当前的根节点htmljava
if(document.documentElement.tagName=='HTML') { alert('document.documentElement is html dom obj'); }
3.srcElement表示事件触发的直接对象浏览器
在js中一般要判断被点击的标签是否是直接触发者,这种方式也是防止事件冒泡的一种有效方式dom
childElem.onclick = function(evt){ var e = evt || window.event; e.target = typeof(e.target)=='undefined'?e.srcElement:e.target; //兼容性调整 if(e.target.tagName==this.tagName){ //dosomething() } }
4.document.all获取全部节点this
if(!(!!document.all.item)) //某些浏览器不支持item(i),须要咱们来从新定义一下 { document.all.item = function(i){ return document.all[i]; } }
5.htmlDOMDocument获取spa
if(!(!!document.all.item)) { document.all.item = function(i){ return document.all[i]; } } document.documentElement; document.all.item(0); document.getElementsByTagName('html').item(0);
6.childNodes,children,parentNode,parentElement一般浏览器支持childNodes和parentNodecode
//无代码
7.document.body,document.title,document.forms都是集合orm
//无代码
8.document能够根据form name属性 表达直接操做form以及form中的input标签htm
document.myform.username.type='text'; document['myform']['username'].type='text'; document.forms['myform'].username; //这里有些奇怪,按理来讲html中name能够相同,但这里只获取第一个name=myform的表单
9.document.defaultView.getComputedStyle 与window.getComputedStyle等价,用于获取currentStyle对象
var alpha = null; if(navigator.userAgent.toLowerCase().indexOf('msie') != -1) { alpha=elem.currentStyle.filter.indexOf("opacity=") >= 0? (parseFloat( elem.currentStyle.filter.match(/opacity=([^)]*)/)[1] )) + '':'100'; }else{ alpha=100*elem.ownerDocument.defaultView.getComputedStyle(elem,null)['opacity']; }
以上作法比较特殊,由于浏览器差别性致使
下面是一般作法
var CStyle=document.defaultView? document.defaultView.getComputedStyle(element,null): element.currentStyle;
try doing it;