javascript - What is the extra content of JQ loop element?
世界只因有你
世界只因有你 2017-06-12 09:28:35
0
2
599

Sometimes when using JQuery's for in and each loops, the attributes related to elements will be looped out. What are these attributes used for? Can you explain it in a simple way? Why does it not appear when using a for loop?

Code:

      
A B C

Console screenshot

世界只因有你
世界只因有你

reply all (2)
迷茫

Because $("a") returns a jQuery object, and it is not an array, but an object. You can judge it through Array.isArray. The extra attributes you mentioned are used To store some things that jQuery needs to use internally. If you want a clean array, you can use $('a').get();

The for loop does not cycle out the redundant attributes. That is because of the problem of your loop. What you pass is [0], [1] and so on. And the redundant attributes you mentioned are not numbers, so naturally they will not It's been recycled.

    漂亮男人

    $("a")itself will get a pseudo array, for whicheach()loops in this array, and each loop processes a jQuery-encapsulated"a"object, which is listed Properties are properties of the jQuery object of this"a". If there is no$(this), directly usethisto print out a DOM object and its attributes. Usingforshould have the same effect.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!