js获取一个对象的所以属性和值
在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' 值为
属性 '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获取一个对象的所以属性和值的更多相关文章
- js 获取和设置css3 属性值的实现方法
众多周知 CSS3 增加了很多属性,在读写的时候就没有原先那么方便了. 如:<div style="left:100px"></div> 只考虑行间样式的话 ...
- jquery】常用的jquery获取表单对象的属性与值
[jquery]常用的jquery获取表单对象的属性与值 1.JQuery的概念 JQuery是一个JavaScript的类库,这个类库集合了很多功能方法,利用类库你可以用一些简单的代码实现一些复杂的 ...
- js-取值&赋值-获取某标签某属性的值
js 取值&赋值-获取某标签某属性的值 CreateTime--2016年10月16日16:35:34 Author:Marydon 1.取值 //方法一 //自定义属性必须用getAtt ...
- js获取键盘按下的键值event.keyCode,event.charCode,event.which的兼容性
js获取键盘按下的键值有event.keyCode,event.charCode和event.which 其中: 谷歌浏览器对event.keyCode,event.charCode和event.wh ...
- bootstrap selectpicker 通过代码指定选中值 BootStrap selectpicker后台动态绑定数据 selectpicker 获取选中option的属性或者值
bootstrap-select使用 bootstrap selectpicker 通过代码指定选中值 $('#subjectno').selectpicker('val',(row.subjectn ...
- JS获取select的value和text值的简单实例
本篇文章主要是对JS获取select的value和text值的简单实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <select id = "cityList ...
- js获取object类型所有的键值对
万物皆对象,而对象完全可以用键值对来表示,所以,在js中,也是通过键值对来表示对象的,在开发中,我在修改的时候,知道属性值可以直接用点.符号来获取值,但是写common.js的时候,发现这个属性名称是 ...
- js中遍历对象的属性和值
今天想看一下js的数组遍历的内容,搜索到了一个关于对象遍历写好的函数,保留一下.以后好用. function allPrpos ( obj ) { // 用来保存所有的属性名称和值 var p ...
- JS获取table表格任意单元格值
jsp页面表格布局 <body onload="show()"> <center> <input type="text" valu ...
随机推荐
- 51nod 1065 最小正子段和 (贪心)
题目:传送门. 题意:中文题. 题解:求前缀和,并且标记每个数的下标,按照前缀和大小进行从小到大排序.随后进行遍历,如果满足下标data[i-1].id<data[i].id&& ...
- 【python升级录】--列表,元组
本节内容 字符串格式化输出 数据运算 for循环 while循环 列表 元组 [字符串格式化输出] 占位符 %s—string,%d—digital,%f —float # __author:&quo ...
- IOS - NSURLSession
NSURLSession是iOS7中新的网络接口,它与咱们熟悉的NSURLConnection是并列的.在程序在前台时,NSURLSession与NSURLConnection可以互为替代工作.注意, ...
- Qt 获取Mac地址
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces(); foreach(QNetworkInterface ...
- August 17th 2016 Week 34th Wednesday
Life is painting a picture, not doing a sum. 生活就像是绘画,而不是做算术. I am too serious about digits. All what ...
- SQL Server之存储过程基础知
什么是存储过程呢?存储过程就是作为可执行对象存放在数据库中的一个或多个SQL命令. 通俗来讲:存储过程其实就是能完成一定操作的一组SQL语句. 那为什么要用存储过程呢?1.存储过程只在创造时进行编译, ...
- 创建Oracle10g ASM数据库
概述 在真正的海量数据库环境中,DBA可能会花费很多的时间来作磁盘管理,比如一个表空间将占满整个磁盘,DBA就需要再添加一块磁盘到操作系统中,然后再在新的磁盘上创建新的数据文件,如果是单个磁 ...
- iOS 文档分享相关
在非系统预览情况下 指定文件打开系统分享菜单 NSString *savedPath = [NSHomeDirectory() stringByAppendingString:[NSString s ...
- 三、jQuery--jQuery实践--搜索框制作
input标签讲解 <input/>作为按钮的type属性:button.submit(后面会有二者对比分析)
- PHP面试题集
汗~~做了一下网络上的php题目,不知不觉做到现在.....把答案贴出来如果有问题请欢迎补充和指正 1.用PHP打印出前一天的时间格式是2006-5-10 22:21:21(2分) $a = da ...