JQuery. Fn. init of parameter analysis

  • 2020-03-30 03:15:11
  • OfStack

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021552.png ">

You can see this in return new jquery.fn.init (selector, context, rootjQuery)
The arguments selector and context are coming from when we call the jQuery method.
So what are the possibilities for selectors and context.

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021553.jpg ">

 

For 4~9 rows in the table may be specific analysis.
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021554.png ">

If the selector is a string, first check whether it is HTML code or #id.
Line 126 if statement: begins with "<" Begin with ">" End, and length > = 3. Then assume that this is an HTML fragment, and here just assume that it is not necessarily the HTML code of hefei, such as "< Div> < Guofsfsdfd>" ;
130 lines of else: not HTML code. Use regular expressions to detect this.
< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021555.png ">
I don't know much about regularization, but I can generally understand that what matches is HTML and id. The result of matching is assigned to match.

After analyzing the selector,context argument, did we forget the rootjQuery argument?
This parameter is defined internally by jQuery. It is not passed in from the outside manually.
From the name we can guess the general situation of this parameter: the jQuery object at the root.
See the source definition:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021556.jpg ">
So when does the program use this parameter?
1. When the document.getelementbyid () lookup fails,

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021557.jpg ">
2. Selector is a function:

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021558.jpg ">
3. Selector is a selector expression, and no context is specified;

< img Alt = "" border = 0 SRC =" / / files.jb51.net/file_images/article/201406/201406091021559.jpg ">


Related articles: