jquery Learning Notes

Source: Internet
Author: User

2016.05.09

    • Idempotent (idempotent, idempotence) is a mathematical or computer concept that is common in abstract algebra. Idempotent is defined in the following ways:
for the monocular operation, if an operation has the same result as the result of doing the operation more than once in the range of a number of times, then we call the Operation Idempotent.   For example, the absolute value operation is an example, in the real number set, there is abs (a) =abs (ABS (a)). For binocular operations, it is required that when the two values of the participating operations are equal, if the results of the operation are equivalent to the two values of the participating operations, the exponentiation of the operation, such as a function of the maximum value of two numbers, is in the power of the real concentration, that is, max (x,x) = x.
    • MVC: MVC is originally in the desktop program, m refers to the data model, v refers to the user interface, C is the controller. The purpose of using MVC is to separate the implementation code for M and v so that the same program can use a different representation.
    • Jquery
First of all, this is very simple, it defines a set of properties, methods, and events that access the HTML Document object, before jquery, we usually directly manipulate the DOM, more familiar API has, and so on. DOM对象 getElementById GetElementByTagName      JQuery , it has an individual name in jquery $ . The simulation code in the above section, which corresponds to jquery in the analog code, is actually a function, and the more detailed point is that the jquery object's factory method, which can construct jquery objects according to different entry parameters, such as:
      1. string expression. such as $ (' span '), $ (' span. class '), $ (' #id ') , and so on

      2. < Span style= "font-size:19px" >html code snippet. such as $ (' <span>text</span> ') and so on

      3. < Span style= "font-size:19px" >dom element. such as $ (DOM)//assuming var dom = document.getElementById (' id ');

      4. js Function. such as $ (function (...) { ... } ); A generic object or array. such as {} , [...] Wait for
, a very important concept, similar to the Jclass instance in analog code, is typically an instance constructed from jquery. JQuery对象 In jquery, we often see the jquery object is this: $(‘#id‘) 、$(‘div‘) and so on. About jquery objects we have to understand the following points:
      1. JQuery对象JQuery原型 prototype All properties and methods that inherit ()
      2. The jquery object is not an array, but it uses an array-like structure to store the elements, and the stored elements are the DOM objects obtained by the selector. Referring to the analog code (instance object) in the previous section, the JClass jquery object has a length property that represents the number of DOM objects stored in the current object, and the DOM objects that are obtained by selection are 0、1、2、3 ... stored as property names by the subscript.
In General, JQuery the JQuery对象 DOM对象 relationship between the three is: a JQuery factory method used to construct; The JQuery对象 jquery object is a class array object, which is stored DOM对象 ; Personal Understanding: jquery is able to use chained operations because jquery objects are constructed by jquery, and in jquery they are stored in an array-like form. The so-called storage element is the DOM object obtained through the selector. So when you use a chained operation , it is equivalent to calling an array-like index to locate it. Its principle is that each step of the jquery operation, the return is a jquery object, so the different operations can be linked together.
    • . InsertAfter () and. After (): Inserts an element from behind an existing element
      . InsertBefore () and. Before (): Outside the existing element, insert the element from the front
      . AppendTo () and. Append (): Inserts an element from behind within an existing element
      . Prependto () and. Prepend (): Inside the existing element, insert the element from the front
Each of the above methods, although the result is the same as the final display, but the biggest difference between the two is that the value returned is different.
  • The delete element uses. Remove () and. Detach (). The difference between the two is that the former does not retain the event of the deleted element, which preserves it, and is useful for re-inserting the document.
  • jquery Design Ideas
    1. The basic design idea and main usage of jquery is to "Select a webpage element and then do something about it";
    2. Provide a variety of powerful filters to filter the result set, narrow the selection results;
    3. Is the final selection of the page element, it can be a series of operations, and all operations can be linked together, in the form of a chain to write it;
    4. is to use the same function to complete the value (getter) and assignment (setter), that is, the "accessor" and "evaluator" in one. Whether the value or the assignment is determined by the parameters of the function;
    5. Provides two sets of methods to manipulate the position of an element in a Web page. One set of methods is to move the element directly, and the other is to move the other elements so that the target element reaches the position we want;
    6. In addition to manipulating the selected elements, it also provides some element-independent tool methods (utility). You can use these methods directly without having to select the elements;
    7. Bind events directly above the page elements;
  • Selector Performance Comparison:
    1. Fastest selector: ID selector and element tag Selector: $ (' #id '), $ (' form '), $ (' input ')
    2. Slower selector: the class selector (Firefox, Safari, Chrome, Opera browser, all with native method Getelementbyclassname (), so the speed is not slow. However, IE5-IE8 does not deploy this method, so this selector will be quite slow in IE. )
    3. Slowest selector: pseudo-class selector and property selector
  • The speed rank of the child element selected in the parent element:
      1. $parent. Find ('. Child '): . Find () Method invokes the native method of the browser (Getelementbyid,getelementbyname,getelementbytagname, and so on), so it is faster;
      2. $ ('. Child ', $parent): This statement means, given a DOM object, then select a child element from it. jquery automatically turns this statement into $.parent.find (' child '), which results in a certain performance penalty. It is slower than the fastest form 5%-10%;
      3. $ ('. Child ', $ (' #parent ')): Within jquery, this statement is converted to $ (' #parent '). Find ('. Child '), which is 23% slower than the fastest form.
      4. $parent. Children ('. Child '): This statement is within jquery and uses $. Sibling () and JavaScript's NextSibling () method, traversing the nodes. It is about slow 50% than the fastest form;
      5. $ (' #parent >. Child '): jquery internally uses the sizzle engine to handle a variety of selectors. The sizzle engine is selected from right to left, so this statement is selected first. Child, and then filters out the parent element #parent, which causes it to be about 70% slower than the fastest form;
      6. $ (' #parent. Child '): This can be used to select multiple sub-elements, so it is slower, probably slower than the fastest form 77%;
  • Event Delegation: The JavaScript event model, which takes the "bubbling" pattern, in other words, the child element's events are "bubbling up" to become the parent element's event.

jquery Learning Notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.