zoukankan      html  css  js  c++  java
  • 遍历jquery的对象

      今天遇到一个问题需要获取tagName,使用jquery,查询了一下,大家说用$("dd").attr("tagName")能获取到,但是得到的返回值是undefined,于是又查询饿了许久,返回遍历了一下jquery封装的对象:

    $("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  

    知识共享许可协议
    作品Tim Zhang创作,采用知识共享署名 3.0 中国大陆许可协议进行许可。 。
  • 相关阅读:
    【整理】Dword、LPSTR、LPWSTR、LPCSTR、LPCWSTR、LPTSTR、LPCTSTR
    C/C++中printf和C++中cout的输出格式
    左值的理解(给渴望学习的新手)
    c++ 指针精髓
    c++中的函数前面加个LRESULT是什么意思啊?
    pb调用vc写的动态链接库文件
    C++问题 & *用法
    vs2008下MFC内存泄露问题一点经验
    mysql5.6.41winx64安装
    开发是一件需要非常小心的工作
  • 原文地址:https://www.cnblogs.com/ccdc/p/2231224.html
Copyright © 2011-2022 走看看