Java programmer's JavaScript learning notes (8 -- jQuery selector)
We plan to complete this note in the following order:
1. concept.
2. Copy and inherit attributes.
3. this/call/apply.
4. Closure/getter/setter.
5. prototype.
6. object-oriented simulation.
7. Basic jQuery mechanism.
8. jQuery selector.
9. jQuery tool method.
10. jQuery-extension at the class level.
11. jQuery-extensions at the "object" level.
12. jQuery-extended selector.
13. jQuery UI.
14. Extend the jQuery UI.
This is Part 1 of the notes. Let's talk about jQuery's selector.
My work has been very busy recently. I haven't updated my notes for a few days.
Finally, today, I have been able to write something quietly.
The claw machine is offline and it depends on its memory. Today's note has no code.
Fortunately, you can use the jQuery selector skillfully. It is not necessary to understand the principle unless you need to implement similar functions or extend the jQuery selector.
Topic 1: four types of Selector
It is actually the four types of parameters passed into the $ () function, which are:
* Dom object, which is identified by the nodeType attribute.
* String: A string can be a css selector expression that matches several regular expressions or an html string.
* Array. Is this only applicable to jQuery clone and pushStack?
* Function, commonly used $ (function () {/* my code here */}).
Topic 2: How does jQuery store the found objects?
Using this [0], this [1], we can understand that the internal storage structure is an array.
Topic 3: How is the find method implemented?
Before reading the source code, I think this is amazing. the browser should only provide document. getElementById/Name/Tag and so on. I have always guessed that jQuery and browser vendors have a leg. Looking back, it is impossible to have a leg with every browser vendor.
After reading the source code, we found that the algorithm is actually implemented based on document. getElementById/Name/Tag.
The "silly" method is not silly. when others are still hesitating to do it, they have already made it.
It can be roughly divided into two steps: first positioning, narrowing down the scope, and then filtering.
Now, let's get here today.