在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. ajax基础语法、ajax做登录、ajax做用户名验证是否可用、ajax做关键字查询动态显示、ajax做用表格显示数据并增加操作列

    AJAX: AJAX 是一种用于创建快速动态网页的技术. 通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新.   ...

  2. 由浅入深剖析.htaccess

    转自:http://blog.csdn.net/21aspnet/article/details/6908025 [-] htaccess文件使用前提 htaccess基本语法介绍 现学现用学习正则表 ...

  3. IntelliJ IDEA 15.0.4常用快捷键整理

    一.背景 最近刚转了IDEA,感觉真是爽的一逼,太智能了,回不去Eclipse了,还有些淡淡的忧伤呢~在使用中很多的快捷键帮了开发的大忙,让我可以达到事半功倍的效果,下面就罗列出来,与大家共同分享. ...

  4. September 26th 2016 Week 40th Monday

    The land didn't move, but moved. The sea wasn't still, yet was still. 大地止而亦行,大海动而亦静. Still waters ru ...

  5. 查询局域网内在线电脑IP

    COLOR 0A CLS @ECHO Off Title 查询局域网内在线电脑IP :send @ECHO off&setlocal enabledelayedexpansion ECHO 正 ...

  6. jQueryEasyUi验证

        多重验证: { field : 'startPort', title : "起始端口", editor: "text", width : 50, edi ...

  7. MVC - 19.Log4net

    下载地址:http://pan.baidu.com/s/1gdxQegN   对于网站来讲,我们不能将异常信息显示给用户, Log4Net用来记录日志,可以将程序运行过程中的信息输出到文件,数据库中等 ...

  8. 与你相遇好幸运,Sail.js创建.sailsrc文件

    在项目根目录下创建.sailsrc文件 {  "generators": {    "modules": {}  },  "hooks": ...

  9. C#关键字ref和out

    using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Di ...

  10. PHP 获取图像信息 getimagesize 函数

    getimagesize() 函数用于获取图像尺寸,类型等信息. imagesx() 函数用于获取图像的宽度. imagesy() 函数用于获取图像的高度. getimagesize() getima ...