遍历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 相关文章推荐
filemanage功能中用到的lib.js
Apr 08 Javascript
javascript 学习之旅 (1)
Feb 05 Javascript
始终在屏幕中间显示Div的代码(css+js)
Mar 10 Javascript
用Javascript实现Windows任务管理器的代码
Mar 27 Javascript
JS实现仿苹果底部任务栏菜单效果代码
Aug 28 Javascript
jQuery Mobile弹出窗、弹出层知识汇总
Jan 05 Javascript
javascript cookie用法基础教程(概念,设置,读取及删除)
Sep 20 Javascript
js实现目录链接,内容跟着目录滚动显示的简单实例
Oct 15 Javascript
React Native react-navigation 导航使用详解
Dec 01 Javascript
详解几十行代码实现一个vue的状态管理
Jan 28 Javascript
详解Vue+ElementUI从零开始搭建自己的网站(一、环境搭建)
Apr 30 Javascript
解决vue的过渡动画无法正常实现问题
Oct 31 Javascript
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
ThinkPHP之用户注册登录留言完整实例
2014/07/22 PHP
php模拟post上传图片实现代码
2016/06/24 PHP
使用一个for循环将N*N的二维数组的所有值置1实现方法
2017/05/29 PHP
PHP安装扩展mcrypt以及相关依赖项深入讲解
2021/03/04 PHP
Javascript下的keyCode键码值表
2007/04/10 Javascript
用js查找法实现当前栏目的高亮显示的代码
2007/11/24 Javascript
js中document.getElementByid、document.all和document.layers区分介绍
2011/12/08 Javascript
40个有创意的jQuery图片和内容滑动及弹出插件收藏集之二
2011/12/31 Javascript
ajax提交表单实现网页无刷新注册示例
2014/05/08 Javascript
利用JavaScript脚本实现滚屏效果的方法
2015/07/07 Javascript
JS鼠标拖拽实例分析
2015/11/23 Javascript
js改变css样式的三种方法推荐
2016/06/28 Javascript
BootStrap Validator对于隐藏域验证和程序赋值即时验证的问题浅析
2016/12/01 Javascript
jquery插件锦集【推荐】
2016/12/16 Javascript
JS动态插入脚本和插入引用外部链接脚本的方法
2018/05/21 Javascript
使用vue.js在页面内组件监听scroll事件的方法
2018/09/11 Javascript
在vue 中使用 less的教程详解
2018/09/26 Javascript
js 实现在2d平面上画8的方法
2018/10/10 Javascript
微信小程序实现评论功能
2018/11/28 Javascript
解决layer弹出层中表单不起作用的问题
2019/09/09 Javascript
详解Java中String JSONObject JSONArray List转换
2020/11/13 Javascript
python操作MongoDB基础知识
2013/11/01 Python
使用python实现rsa算法代码
2016/02/17 Python
Python使用openpyxl读写excel文件的方法
2017/06/30 Python
利用python为运维人员写一个监控脚本
2018/03/25 Python
python版大富翁源代码分享
2018/11/19 Python
python监控进程状态,记录重启时间及进程号的实例
2019/07/15 Python
python dumps和loads区别详解
2020/02/04 Python
Java面向对象面试题
2016/12/26 面试题
高中毕业自我评价
2014/02/08 职场文书
2014年五一活动策划方案
2014/03/15 职场文书
2014最新开业庆典策划方案(5篇)
2014/09/15 职场文书
公司授权委托书样本
2014/09/15 职场文书
校园会短篇的广播稿
2014/10/21 职场文书
优秀护士事迹材料
2014/12/25 职场文书
医院合作意向书范本
2015/05/08 职场文书