在HTML DOM中,获取某个元素对象的时候,往往记不住它的很多属性,可以通过下面的例子来查找一下:

 <!DOCTYPE html>
<html>
<body>
<h1>获取对象属性和值</h1>
<div id="div1" class="div">fdsfs</div>
<script type="text/javascript">
var myObject = document.getElementById("div1");
//遍历对象的所有属性
for (prop in myObject)
{
document.write("属性 '" + prop + "' 值为 " + myObject[prop]);
document.write("<br> ");
}
</script>
</body>
</html>

查询以后你会获得很多信息:

属性 'align' 值为
属性 'click' 值为 function click() {
[native code]
}

属性 'focus' 值为 function focus() {
[native code]
}

属性 'blur' 值为 function blur() {
[native code]
}

属性 'title' 值为
属性 'lang' 值为
属性 'dir' 值为
属性 'dataset' 值为 [object DOMStringMap]
属性 'itemScope' 值为 false
属性 'itemType' 值为
属性 'itemId' 值为
属性 'itemRef' 值为
属性 'itemProp' 值为
属性 'properties' 值为 [object HTMLPropertiesCollection]
属性 'itemValue' 值为 null
属性 'hidden' 值为 false
属性 'tabIndex' 值为 -1
属性 'accessKey' 值为
属性 'accessKeyLabel' 值为
属性 'draggable' 值为 false
属性 'contentEditable' 值为 inherit
属性 'isContentEditable' 值为 false
属性 'contextMenu' 值为 null
属性 'spellcheck' 值为 false
属性 'style' 值为 [object CSS2Properties]
属性 'oncopy' 值为 null
属性 'oncut' 值为 null
属性 'onpaste' 值为 null
属性 'offsetParent' 值为 [object HTMLBodyElement]
属性 'offsetTop' 值为 86
属性 'offsetLeft' 值为 8
属性 'offsetWidth' 值为 600
属性 'offsetHeight' 值为 22
属性 'onabort' 值为 null
属性 'onblur' 值为 null
属性 'onfocus' 值为 null
属性 'oncanplay' 值为 null
属性 'oncanplaythrough' 值为 null
属性 'onchange' 值为 null
属性 'onclick' 值为 null
属性 'oncontextmenu' 值为 null
属性 'ondblclick' 值为 null
属性 'ondrag' 值为 null
属性 'ondragend' 值为 null
属性 'ondragenter' 值为 null
属性 'ondragleave' 值为 null
属性 'ondragover' 值为 null
属性 'ondragstart' 值为 null
属性 'ondrop' 值为 null
属性 'ondurationchange' 值为 null
属性 'onemptied' 值为 null
属性 'onended' 值为 null
属性 'oninput' 值为 null
属性 'oninvalid' 值为 null
属性 'onkeydown' 值为 null
属性 'onkeypress' 值为 null
属性 'onkeyup' 值为 null
属性 'onload' 值为 null
属性 'onloadeddata' 值为 null
属性 'onloadedmetadata' 值为 null
属性 'onloadstart' 值为 null
属性 'onmousedown' 值为 null
属性 'onmouseenter' 值为 null
属性 'onmouseleave' 值为 null
属性 'onmousemove' 值为 null
属性 'onmouseout' 值为 null
属性 'onmouseover' 值为 null
属性 'onmouseup' 值为 null
属性 'onpause' 值为 null
属性 'onplay' 值为 null
属性 'onplaying' 值为 null
属性 'onprogress' 值为 null
属性 'onratechange' 值为 null
属性 'onreset' 值为 null
属性 'onresize' 值为 null
属性 'onscroll' 值为 null
属性 'onseeked' 值为 null
属性 'onseeking' 值为 null
属性 'onselect' 值为 null
属性 'onshow' 值为 null
属性 'onstalled' 值为 null
属性 'onsubmit' 值为 null
属性 'onsuspend' 值为 null
属性 'ontimeupdate' 值为 null
属性 'onvolumechange' 值为 null
属性 'onwaiting' 值为 null
属性 'onmozfullscreenchange' 值为 null
属性 'onmozfullscreenerror' 值为 null
属性 'onmozpointerlockchange' 值为 null
属性 'onmozpointerlockerror' 值为 null
属性 'onerror' 值为 null
属性 'getAttribute' 值为 function getAttribute() {
[native code]
}
属性 'getAttributeNS' 值为 function getAttributeNS() {
[native code]
}
属性 'setAttribute' 值为 function setAttribute() {
[native code]
}
属性 'setAttributeNS' 值为 function setAttributeNS() {
[native code]
}
属性 'removeAttribute' 值为 function removeAttribute() {
[native code]
}
属性 'removeAttributeNS' 值为 function removeAttributeNS() {
[native code]
}
属性 'hasAttribute' 值为 function hasAttribute() {
[native code]
}
属性 'hasAttributeNS' 值为 function hasAttributeNS() {
[native code]
}
属性 'hasAttributes' 值为 function hasAttributes() {
[native code]
}
属性 'closest' 值为 function closest() {
[native code]
}
属性 'matches' 值为 function matches() {
[native code]
}
属性 'getElementsByTagName' 值为 function getElementsByTagName() {
[native code]
}
属性 'getElementsByTagNameNS' 值为 function getElementsByTagNameNS() {
[native code]
}
属性 'getElementsByClassName' 值为 function getElementsByClassName() {
[native code]
}
属性 'mozMatchesSelector' 值为 function mozMatchesSelector() {
[native code]
}
属性 'setCapture' 值为 function setCapture() {
[native code]
}
属性 'releaseCapture' 值为 function releaseCapture() {
[native code]
}
属性 'mozRequestFullScreen' 值为 function mozRequestFullScreen() {
[native code]
}
属性 'mozRequestPointerLock' 值为 function mozRequestPointerLock() {
[native code]
}
属性 'getAttributeNode' 值为 function getAttributeNode() {
[native code]
}
属性 'setAttributeNode' 值为 function setAttributeNode() {
[native code]
}
属性 'removeAttributeNode' 值为 function removeAttributeNode() {
[native code]
}
属性 'getAttributeNodeNS' 值为 function getAttributeNodeNS() {
[native code]
}
属性 'setAttributeNodeNS' 值为 function setAttributeNodeNS() {
[native code]
}
属性 'getClientRects' 值为 function getClientRects() {
[native code]
}
属性 'getBoundingClientRect' 值为 function getBoundingClientRect() {
[native code]
}
属性 'scrollIntoView' 值为 function scrollIntoView() {
[native code]
}
属性 'scroll' 值为 function scroll() {
[native code]
}
属性 'scrollTo' 值为 function scrollTo() {
[native code]
}
属性 'scrollBy' 值为 function scrollBy() {
[native code]
}
属性 'insertAdjacentHTML' 值为 function insertAdjacentHTML() {
[native code]
}
属性 'querySelector' 值为 function querySelector() {
[native code]
}
属性 'querySelectorAll' 值为 function querySelectorAll() {
[native code]
}
属性 'remove' 值为 function remove() {
[native code]
}
属性 'tagName' 值为 DIV
属性 'id' 值为 div1
属性 'className' 值为 div
属性 'classList' 值为 div
属性 'attributes' 值为 [object NamedNodeMap]
属性 'onwheel' 值为 null
属性 'scrollTop' 值为 0
属性 'scrollLeft' 值为 0
属性 'scrollWidth' 值为 600
属性 'scrollHeight' 值为 22
属性 'clientTop' 值为 0
属性 'clientLeft' 值为 0
属性 'clientWidth' 值为 600
属性 'clientHeight' 值为 22
属性 'scrollTopMax' 值为 0
属性 'scrollLeftMax' 值为 0
属性 'innerHTML' 值为 fdsfs
属性 'outerHTML' 值为

fdsfs

属性 'previousElementSibling' 值为 [object HTMLHeadingElement]
属性 'nextElementSibling' 值为 [object HTMLScriptElement]
属性 'children' 值为 [object HTMLCollection]
属性 'firstElementChild' 值为 null
属性 'lastElementChild' 值为 null
属性 'childElementCount' 值为 0
属性 'hasChildNodes' 值为 function hasChildNodes() {
[native code]
}
属性 'insertBefore' 值为 function insertBefore() {
[native code]
}
属性 'appendChild' 值为 function appendChild() {
[native code]
}
属性 'replaceChild' 值为 function replaceChild() {
[native code]
}
属性 'removeChild' 值为 function removeChild() {
[native code]
}
属性 'normalize' 值为 function normalize() {
[native code]
}
属性 'cloneNode' 值为 function cloneNode() {
[native code]
}
属性 'isEqualNode' 值为 function isEqualNode() {
[native code]
}
属性 'compareDocumentPosition' 值为 function compareDocumentPosition() {
[native code]
}
属性 'contains' 值为 function contains() {
[native code]
}
属性 'lookupPrefix' 值为 function lookupPrefix() {
[native code]
}
属性 'lookupNamespaceURI' 值为 function lookupNamespaceURI() {
[native code]
}
属性 'isDefaultNamespace' 值为 function isDefaultNamespace() {
[native code]
}
属性 'nodeType' 值为 1
属性 'nodeName' 值为 DIV
属性 'baseURI' 值为 http://www.runoob.com/try/demo_source/result.php?x=0.5273678891388178
属性 'ownerDocument' 值为 [object HTMLDocument]
属性 'parentNode' 值为 [object HTMLBodyElement]
属性 'parentElement' 值为 [object HTMLBodyElement]
属性 'childNodes' 值为 [object NodeList]
属性 'firstChild' 值为 [object Text]
属性 'lastChild' 值为 [object Text]
属性 'previousSibling' 值为 [object Text]
属性 'nextSibling' 值为 [object Text]
属性 'nodeValue' 值为 null
属性 'textContent' 值为 fdsfs
属性 'namespaceURI' 值为 http://www.w3.org/1999/xhtml
属性 'prefix' 值为 null
属性 'localName' 值为 div
属性 'ELEMENT_NODE' 值为 1
属性 'ATTRIBUTE_NODE' 值为 2
属性 'TEXT_NODE' 值为 3
属性 'CDATA_SECTION_NODE' 值为 4
属性 'ENTITY_REFERENCE_NODE' 值为 5
属性 'ENTITY_NODE' 值为 6
属性 'PROCESSING_INSTRUCTION_NODE' 值为 7
属性 'COMMENT_NODE' 值为 8
属性 'DOCUMENT_NODE' 值为 9
属性 'DOCUMENT_TYPE_NODE' 值为 10
属性 'DOCUMENT_FRAGMENT_NODE' 值为 11
属性 'NOTATION_NODE' 值为 12
属性 'DOCUMENT_POSITION_DISCONNECTED' 值为 1
属性 'DOCUMENT_POSITION_PRECEDING' 值为 2
属性 'DOCUMENT_POSITION_FOLLOWING' 值为 4
属性 'DOCUMENT_POSITION_CONTAINS' 值为 8
属性 'DOCUMENT_POSITION_CONTAINED_BY' 值为 16
属性 'DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC' 值为 32
属性 'addEventListener' 值为 function addEventListener() {
[native code]
}
属性 'removeEventListener' 值为 function removeEventListener() {
[native code]
}
属性 'dispatchEvent' 值为 function dispatchEvent() {
[native code]
}

上面黑体的几乎就是最常见的属性了,其他的可能都不太见过。。。

js获取一个对象的所以属性和值的更多相关文章

  1. js 获取和设置css3 属性值的实现方法

    众多周知 CSS3 增加了很多属性,在读写的时候就没有原先那么方便了. 如:<div style="left:100px"></div> 只考虑行间样式的话 ...

  2. jquery】常用的jquery获取表单对象的属性与值

    [jquery]常用的jquery获取表单对象的属性与值 1.JQuery的概念 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用一些简单的代码实现一些复杂的 ...

  3. js-取值&赋值-获取某标签某属性的值

      js 取值&赋值-获取某标签某属性的值 CreateTime--2016年10月16日16:35:34 Author:Marydon 1.取值 //方法一 //自定义属性必须用getAtt ...

  4. js获取键盘按下的键值event.keyCode,event.charCode,event.which的兼容性

    js获取键盘按下的键值有event.keyCode,event.charCode和event.which 其中: 谷歌浏览器对event.keyCode,event.charCode和event.wh ...

  5. bootstrap selectpicker 通过代码指定选中值 BootStrap selectpicker后台动态绑定数据 selectpicker 获取选中option的属性或者值

    bootstrap-select使用 bootstrap selectpicker 通过代码指定选中值 $('#subjectno').selectpicker('val',(row.subjectn ...

  6. JS获取select的value和text值的简单实例

    本篇文章主要是对JS获取select的value和text值的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <select id = "cityList ...

  7. js获取object类型所有的键值对

    万物皆对象,而对象完全可以用键值对来表示,所以,在js中,也是通过键值对来表示对象的,在开发中,我在修改的时候,知道属性值可以直接用点.符号来获取值,但是写common.js的时候,发现这个属性名称是 ...

  8. js中遍历对象的属性和值

    今天想看一下js的数组遍历的内容,搜索到了一个关于对象遍历写好的函数,保留一下.以后好用. function allPrpos ( obj ) {   // 用来保存所有的属性名称和值   var p ...

  9. JS获取table表格任意单元格值

    jsp页面表格布局 <body onload="show()"> <center> <input type="text" valu ...

随机推荐

  1. iOS多线程编程之NSThread的使用

      目录(?)[-] 简介 iOS有三种多线程编程的技术分别是 三种方式的有缺点介绍 NSThread的使用 NSThread 有两种直接创建方式 参数的意义 PS不显式创建线程的方法 下载图片的例子 ...

  2. Android笔记:ListView

    listview属性 android:divider属性,可以指定ListView 分隔线的颜色,#0000 表示将分隔线设为透明色. listview效率的问题 adapter的三个参数int po ...

  3. A Horrible Poem(bzoj 2795)

    Description 给出一个由小写英文字母组成的字符串S,再给出q个询问,要求回答S某个子串的最短循环节.如果字符串B是字符串A的循环节,那么A可以由B重复若干次得到. Input 第一行一个正整 ...

  4. XMPP框架下微信项目总结(1)环境配置

    xmpp介绍 xmpp基于模块开发的 无须自己写请求 (登陆,注册,获取好友列表,添加/删除好友等) ------>简介 ------------------------- ----->工 ...

  5. Rotate partitions in DB2 on z

    Rotating partitions   You can use the ALTER TABLE statement to rotate any logical partition to becom ...

  6. Struts2之类型转换器

    一.类型转换器的应用场景 类型转换是OGNL的一部分,默认的八种基本类型.String.Date会使用类型转换,但是更复杂的类型转换就需要我们自定义了(虽然这个东西一般根本用不到),OGNL可以应用在 ...

  7. Weblogic监控指标

    http://blog.csdn.net/a_dreaming_fish/article/details/50592042

  8. java 泛型 -- 泛型类,泛型接口,泛型方法

    泛型T泛型的许多最佳例子都来自集合框架,因为泛型让您在保存在集合中的元素上指定类型约束.在定义泛型类或声明泛型类的变量时,使用尖括号来指定形式类型参数.形式类型参数与实际类型参数之间的关系类似于形式方 ...

  9. 你可能不知道的java、python、JavaScript以及jquary循环语句的区别

    一.概述 java循环语句分为四种形式,分别是 while, do/while, for, foreach: python中循环语句有两种,while,for: JavaScript中循环语句有四种, ...

  10. SVN的忽略和只读使用方法学习记录

    前言,先扯几句.最近学了GIT,虽然很肤浅,但是也算是用上了分布式版本管理控制系统.Linus很牛,他也很厌烦SVN,而我看这些都是工具,是否拿来使用主要看是否顺手.我赞同分布式版本管理控制,它有诸多 ...