在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. Android Studio新建了一个项目提示Error:Unable to start the daemon process

    提示如下错误:

  2. 微信支付官方.net版之坑你没商量

    最近开始弄支付这块,先是支付宝手机网站支付,也是坑了我许久,不过还好,问题不大. 让我们看看微信支付有多少坑 微信商户平台,你们知道么(我前天才知道,别笑我) 登录地址:https://mch.wei ...

  3. Mysql undo与redo Log

    http://mysql.taobao.org/monthly/2015/04/01/ http://www.cnblogs.com/Bozh/archive/2013/03/18/2966494.h ...

  4. c语言运算符

     一.op=形式的赋值操作符 int a=0; a+=1; //等价于 a=a+1;// a*=1;  二.op=类表达式 int a=10,b=5; a/=b;//等价于a=a/b; a*=b+1; ...

  5. lnmp初步学习知识整理

    Linux常用30个命令 1.帮助命令 1) man 就是manual的缩写,用来查看系统中自带的各种参考手册(一般linux系统中自带英文手册)! man 命令名 //查看该命令的介绍 2) 命令名 ...

  6. 加载gif动画的三种方式

    GifView.h/** * 调用结束就开始播放动画,如果需要用户指定何时播放的话,只需要把timer的开始放到合适的位置.通过对CFDictonaryRaf 也就是gifProperties的改变, ...

  7. C#的初始化器

    using System; using System.Collections; using System.Collections.Generic; using System.IO; using Sys ...

  8. 在 Android Studio中恢复已经被移除的Module

    假设名为app的Module已经被移除,则他的图标上小手机图标将会消失.此时如下图编辑settings.gradle,然后点击如图按钮Sync Project with Gradle Files即可. ...

  9. windows64系统中mysql64位绿色安装

    将下载压缩包解压到任意目录 配置安装文件: # For advice on how to change settings please see# http://dev.mysql.com/doc/re ...

  10. 在Salesforce中将 Decimal 数据转换成美元格式

    闲言少叙,直接上代码(Apex Class 中的方法): private string ConvertToMoneyFormat(decimal price){ if (price == null | ...