遍历jquery对象的代码分享


Posted in Javascript onNovember 02, 2011
$("dd").bind("click",function(e){ 
var $obj = $(e.target); 
var i=0; 
for (var x in $obj){ 
i++; 
var $hr=(i%5==0) ? "<hr />" : " "; 
document.write(x+" "+$hr); 
} 
});

遍历结果:
0 length prevObject context selector
--------------------------------------------------------------------------------
constructor init jquery size toArray
--------------------------------------------------------------------------------
get pushStack each ready eq
--------------------------------------------------------------------------------
first last slice map end
--------------------------------------------------------------------------------
push sort splice extend data
--------------------------------------------------------------------------------
removeData queue dequeue delay clearQueue
--------------------------------------------------------------------------------
promise attr removeAttr prop removeProp
--------------------------------------------------------------------------------
addClass removeClass toggleClass hasClass val
--------------------------------------------------------------------------------
bind one unbind delegate undelegate
--------------------------------------------------------------------------------
trigger triggerHandler toggle hover live
--------------------------------------------------------------------------------
die blur focus focusin focusout
--------------------------------------------------------------------------------
load resize scroll unload click
--------------------------------------------------------------------------------
dblclick mousedown mouseup mousemove mouseover
--------------------------------------------------------------------------------
mouseout mouseenter mouseleave change select
--------------------------------------------------------------------------------
submit keydown keypress keyup error
--------------------------------------------------------------------------------
find has not filter is
--------------------------------------------------------------------------------
closest index add andSelf parent
--------------------------------------------------------------------------------
parents parentsUntil next prev nextAll
--------------------------------------------------------------------------------
prevAll nextUntil prevUntil siblings children
--------------------------------------------------------------------------------
contents text wrapAll wrapInner wrap
--------------------------------------------------------------------------------
unwrap append prepend before after
--------------------------------------------------------------------------------
remove empty clone html replaceWith
--------------------------------------------------------------------------------
detach domManip appendTo prependTo insertBefore
--------------------------------------------------------------------------------
insertAfter replaceAll css serialize serializeArray
--------------------------------------------------------------------------------
ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess
--------------------------------------------------------------------------------
ajaxSend show hide _toggle fadeTo
--------------------------------------------------------------------------------
animate stop slideDown slideUp slideToggle
--------------------------------------------------------------------------------
fadeIn fadeOut fadeToggle offset position
--------------------------------------------------------------------------------
offsetParent scrollLeft scrollTop innerHeight outerHeight
--------------------------------------------------------------------------------
height innerWidth outerWidth width
再遍历:
$("dd").bind("click",function(e){ 
var $obj = $(e.target); 
var i=0; 
for (var x in $obj[0]){ 
i++; 
var $hr=(i%5==0) ? "<hr />" : " "; 
document.write(x+" "+$hr); 
} 
});

遍历结果:
querySelector querySelectorAll scrollTop scrollLeft scrollHeight
--------------------------------------------------------------------------------
scrollWidth clientTop clientLeft clientHeight clientWidth
--------------------------------------------------------------------------------
firstElementChild lastElementChild previousElementSibling nextElementSibling childElementCount
--------------------------------------------------------------------------------
children classList setCapture getElementsByClassName getClientRects
--------------------------------------------------------------------------------
getBoundingClientRect releaseCapture mozMatchesSelector addEventListener removeEventListener
--------------------------------------------------------------------------------
dispatchEvent style contentEditable isContentEditable offsetParent
--------------------------------------------------------------------------------
innerHTML offsetLeft offsetTop offsetHeight offsetWidth
--------------------------------------------------------------------------------
scrollIntoView id title lang dir
--------------------------------------------------------------------------------
className accessKey blur focus click
--------------------------------------------------------------------------------
tagName removeAttributeNS removeAttribute getAttribute getElementsByTagName
--------------------------------------------------------------------------------
setAttribute getElementsByTagNameNS hasAttributeNS setAttributeNS hasAttribute
--------------------------------------------------------------------------------
getAttributeNS nodeName nodeValue nodeType parentNode
--------------------------------------------------------------------------------
childNodes firstChild lastChild previousSibling nextSibling
--------------------------------------------------------------------------------
attributes ownerDocument namespaceURI prefix localName
--------------------------------------------------------------------------------
baseURI textContent setUserData getUserData insertBefore
--------------------------------------------------------------------------------
replaceChild removeChild appendChild hasChildNodes cloneNode
--------------------------------------------------------------------------------
normalize isSupported hasAttributes compareDocumentPosition isSameNode
--------------------------------------------------------------------------------
lookupPrefix isDefaultNamespace lookupNamespaceURI isEqualNode getAttributeNode
--------------------------------------------------------------------------------
setAttributeNode removeAttributeNode getAttributeNodeNS setAttributeNodeNS ELEMENT_NODE
--------------------------------------------------------------------------------
ATTRIBUTE_NODE TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE
--------------------------------------------------------------------------------
PROCESSING_INSTRUCTION_NODE COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE
--------------------------------------------------------------------------------
NOTATION_NODE DOCUMENT_POSITION_DISCONNECTED DOCUMENT_POSITION_PRECEDING DOCUMENT_POSITION_FOLLOWING DOCUMENT_POSITION_CONTAINS
--------------------------------------------------------------------------------
DOCUMENT_POSITION_CONTAINED_BY DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC hidden tabIndex draggable
--------------------------------------------------------------------------------
spellcheck dataset
于是用$("dd")[0].tagName 可以获得tagName.
参考:http://www.mkyong.com/jquery/jquery-how-to-get-the-tag-name/
然后与$("a")遍历的结果对比
$("a").bind("click",function(e){ 
var $obj = $(e.target); 
var i=0; 
for (var x in $obj){ 
i++; 
var $hr=(i%5==0) ? "<hr />" : " "; 
document.write(x+" "+$hr); 
} 
});

遍历结果:
0 context length constructor init
--------------------------------------------------------------------------------
selector jquery size toArray get
--------------------------------------------------------------------------------
pushStack each ready eq first
--------------------------------------------------------------------------------
last slice map end push
--------------------------------------------------------------------------------
sort splice extend data removeData
--------------------------------------------------------------------------------
queue dequeue delay clearQueue promise
--------------------------------------------------------------------------------
attr removeAttr prop removeProp addClass
--------------------------------------------------------------------------------
removeClass toggleClass hasClass val bind
--------------------------------------------------------------------------------
one unbind delegate undelegate trigger
--------------------------------------------------------------------------------
triggerHandler toggle hover live die
--------------------------------------------------------------------------------
blur focus focusin focusout load
--------------------------------------------------------------------------------
resize scroll unload click dblclick
--------------------------------------------------------------------------------
mousedown mouseup mousemove mouseover mouseout
--------------------------------------------------------------------------------
mouseenter mouseleave change select submit
--------------------------------------------------------------------------------
keydown keypress keyup error find
--------------------------------------------------------------------------------
has not filter is closest
--------------------------------------------------------------------------------
index add andSelf parent parents
--------------------------------------------------------------------------------
parentsUntil next prev nextAll prevAll
--------------------------------------------------------------------------------
nextUntil prevUntil siblings children contents
--------------------------------------------------------------------------------
text wrapAll wrapInner wrap unwrap
--------------------------------------------------------------------------------
append prepend before after remove
--------------------------------------------------------------------------------
empty clone html replaceWith detach
--------------------------------------------------------------------------------
domManip appendTo prependTo insertBefore insertAfter
--------------------------------------------------------------------------------
replaceAll css serialize serializeArray ajaxStart
--------------------------------------------------------------------------------
ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend
--------------------------------------------------------------------------------
show hide _toggle fadeTo animate
--------------------------------------------------------------------------------
stop slideDown slideUp slideToggle fadeIn
--------------------------------------------------------------------------------
fadeOut fadeToggle offset position offsetParent
--------------------------------------------------------------------------------
scrollLeft scrollTop innerHeight outerHeight height
--------------------------------------------------------------------------------
innerWidth outerWidth width

再遍历:

$("a").bind("click",function(e){ 
var $obj = $(e.target); 
var i=0; 
for (var x in $obj[0]){ 
i++; 
var $hr=(i%5==0) ? "<hr />" : " "; 
document.write(x+" "+$hr); 
} 
});

遍历结果:
jQuery16407028609993839658 querySelector querySelectorAll scrollTop scrollLeft
--------------------------------------------------------------------------------
scrollHeight scrollWidth clientTop clientLeft clientHeight
--------------------------------------------------------------------------------
clientWidth firstElementChild lastElementChild previousElementSibling nextElementSibling
--------------------------------------------------------------------------------
childElementCount children classList setCapture getElementsByClassName
--------------------------------------------------------------------------------
getClientRects getBoundingClientRect releaseCapture mozMatchesSelector addEventListener
--------------------------------------------------------------------------------
removeEventListener dispatchEvent style contentEditable isContentEditable
--------------------------------------------------------------------------------
offsetParent innerHTML offsetLeft offsetTop offsetHeight
--------------------------------------------------------------------------------
offsetWidth scrollIntoView href rel target
--------------------------------------------------------------------------------
name text search hash id
--------------------------------------------------------------------------------
title lang dir className accessKey
--------------------------------------------------------------------------------
blur focus click tagName removeAttributeNS
--------------------------------------------------------------------------------
removeAttribute getAttribute getElementsByTagName setAttribute getElementsByTagNameNS
--------------------------------------------------------------------------------
hasAttributeNS setAttributeNS hasAttribute getAttributeNS nodeName
--------------------------------------------------------------------------------
nodeValue nodeType parentNode childNodes firstChild
--------------------------------------------------------------------------------
lastChild previousSibling nextSibling attributes ownerDocument
--------------------------------------------------------------------------------
namespaceURI prefix localName baseURI textContent
--------------------------------------------------------------------------------
setUserData getUserData insertBefore replaceChild removeChild
--------------------------------------------------------------------------------
appendChild hasChildNodes cloneNode normalize isSupported
--------------------------------------------------------------------------------
hasAttributes compareDocumentPosition isSameNode lookupPrefix isDefaultNamespace
--------------------------------------------------------------------------------
lookupNamespaceURI isEqualNode tabIndex ELEMENT_NODE ATTRIBUTE_NODE
--------------------------------------------------------------------------------
TEXT_NODE CDATA_SECTION_NODE ENTITY_REFERENCE_NODE ENTITY_NODE PROCESSING_INSTRUCTION_NODE
--------------------------------------------------------------------------------
COMMENT_NODE DOCUMENT_NODE DOCUMENT_TYPE_NODE DOCUMENT_FRAGMENT_NODE NOTATION_NODE
--------------------------------------------------------------------------------
DOCUMENT_POSITION_DISCONNECTED DOCUMENT_POSITION_PRECEDING DOCUMENT_POSITION_FOLLOWING DOCUMENT_POSITION_CONTAINS DOCUMENT_POSITION_CONTAINED_BY
--------------------------------------------------------------------------------
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC getAttributeNode setAttributeNode removeAttributeNode getAttributeNodeNS
--------------------------------------------------------------------------------
setAttributeNodeNS ping hreflang type protocol
--------------------------------------------------------------------------------
host hostname port pathname charset
--------------------------------------------------------------------------------
coords rev shape hidden draggable
--------------------------------------------------------------------------------
spellcheck dataset
jQuery Get Tag Name
<html> 
<head> 
<title>jQuery Get Tag Name</title> 
<script type="text/javascript" src="jquery-1.3.2.min.js"></script> 
</head> 
<script type="text/javascript"> 
$(document).ready(function(){ var $tag = $('p')[0].tagName; //'P' 
alert($tag); 
var $tag = $('.classTag1')[0].tagName; //'DIV' 
alert($tag); 
var $tag = $('#idTag1')[0].tagName; //'DIV' 
alert($tag); 
var $tag = $('p').get(0).tagName; //'P' 
alert($tag); 
var $tag = $('.classTag1').get(0).tagName; //'DIV' 
alert($tag); 
var $tag = $('#idTag1').get(0).tagName; //'DIV' 
alert($tag); 
}); 
</script> 
<body> 
<h1>jQuery Get Tag Name</h1> 
<p> 
This is paragrah 1 
</p> 
<div class="classTag1"> 
This is class='classTag1' 
</div> 
<div id="idTag1"> 
This is id='idTag1' 
</div> 
</body> 
</html>
Javascript 相关文章推荐
Jquery 实现Tab效果 思路是js思路
Mar 02 Javascript
javascript一个无懈可击的实例化XMLHttpRequest的方法
Oct 13 Javascript
使用js修改客户端注册表的方法
Aug 09 Javascript
jQuery 属性选择器element[herf*='value']使用示例
Oct 20 Javascript
js复制网页内容并兼容各主流浏览器的代码
Dec 17 Javascript
详解JavaScript的Polymer框架中的通知交互
Jul 29 Javascript
javascript实现对表格元素进行排序操作
Nov 18 Javascript
jQuery页面刷新(局部、全部)问题分析
Jan 09 Javascript
JS+canvas绘制的动态机械表动画效果
Sep 12 Javascript
深入理解Node module模块
Mar 26 Javascript
如何让微信小程序页面之间的通信不再变困难
Jun 03 Javascript
在vue中通过render函数给子组件设置ref操作
Nov 17 Vue.js
jquery 笔记 事件
Nov 02 #Javascript
分页栏的web标准实现
Nov 01 #Javascript
jquery键盘事件使用介绍
Nov 01 #Javascript
JS鼠标事件大全 推荐收藏
Nov 01 #Javascript
EasyUI中的tree用法介绍
Nov 01 #Javascript
jQuery代码优化 事件委托篇
Nov 01 #Javascript
jQuery代码优化 遍历篇
Nov 01 #Javascript
You might like
咖啡的植物学知识
2021/03/03 咖啡文化
PHP mb_convert_encoding 获取字符串编码类型实现代码
2009/04/26 PHP
php设计模式  Command(命令模式)
2011/06/17 PHP
关于mysql字符集设置了character_set_client=binary 在gbk情况下会出现表描述是乱码的情况
2013/01/06 PHP
如何让thinkphp在模型中自动完成session赋值小教程
2014/09/05 PHP
php提交post数组参数实例分析
2015/12/17 PHP
php阳历转农历优化版
2016/08/08 PHP
Laravel使用memcached缓存对文章增删改查进行优化的方法
2016/10/08 PHP
PHP 芝麻信用接入的注意事项
2016/12/01 PHP
共享自己写一个框架DreamScript
2007/01/20 Javascript
新浪刚打开页面出来的全屏广告代码
2007/04/02 Javascript
javascript showModalDialog模态对话框使用说明
2009/12/31 Javascript
制作高质量的JQuery Plugin 插件的方法
2010/04/20 Javascript
PHP abstract与interface之间的区别
2013/11/11 Javascript
jquery动态增加删除表格行的小例子
2013/11/14 Javascript
js日期范围初始化得到前一个月日期的方法
2015/05/05 Javascript
javascript DIV实现跟随鼠标移动
2020/03/19 Javascript
JavaScript获取移动设备型号的实现代码(JS获取手机型号和系统)
2018/03/10 Javascript
在小程序中推送模板消息的实现方法
2019/07/22 Javascript
vue项目中微信登录的实现操作
2020/09/08 Javascript
[03:59]第二届DOTA2亚洲邀请赛选手传记-VGJ.rOtk
2017/04/03 DOTA
使用PYTHON创建XML文档
2012/03/01 Python
python的Template使用指南
2014/09/11 Python
利用Python的Flask框架来构建一个简单的数字商品支付解决方案
2015/03/31 Python
详解Python中的array数组模块相关使用
2016/07/05 Python
使用python和pygame绘制繁花曲线的方法
2018/02/24 Python
Python实现滑动平均(Moving Average)的例子
2019/08/24 Python
Python数据可视化:幂律分布实例详解
2019/12/07 Python
Python -m参数原理及使用方法解析
2020/08/21 Python
超级英雄、电影和电视、乐队和音乐T恤:Loud Clothing
2019/09/01 全球购物
be2台湾单身男女交友:全球网路婚姻介绍的领导品牌
2019/10/11 全球购物
介绍一下Python中webbrowser的用法
2013/05/07 面试题
国外的一些J2EE面试题一
2012/10/13 面试题
办公室文员工作职责
2014/01/31 职场文书
计算机专业自荐信
2014/05/24 职场文书
机关党员四风问题个人整改措施
2014/10/26 职场文书