jquery common form operation set of functions (1/4)

Source: Internet
Author: User

1. References to page elements
The $ () reference element in jquery includes methods such as ID, class, element name, and hierarchy of elements and Dom or XPath conditions, and the returned object is a jquery object (a collection object) that cannot directly invoke the DOM-defined method.
2. The conversion of jquery object and Dom object
Only jquery objects can use the method defined by jquery. Note that there is a difference between a DOM object and a jquery object, and the method is invoked with a DOM object or a jquery object in mind.
Ordinary DOM objects can generally be converted to jquery objects by $ ().
such as: $ (document.getElementById ("MSG") is a jquery object, you can use the method of jquery.
Because the jquery object itself is a collection. So if the jquery object is to be converted to a DOM object, one of these items must be removed, which is generally accessible through the index.
such as: $ ("#msg") [0],$ ("div"). EQ (1) [0],$ ("div"). get () [1],$ ("TD") [5] These are DOM objects, you can use the methods in DOM, but you can no longer use the jquery method.
The following are the correct ways to do this:
3, how to get a jquery collection of an item
For an acquired collection of elements, getting an item (specified by index) can be obtained by using an EQ or get (n) method or an index number, noting that the EQ returns a jquery object, while get (n) and the index return the DOM element object. For jquery objects, only jquery can be used, and DOM objects can only use the DOM method, such as to get a third
The contents of the element. There are two ways to:
$ ("div"). EQ (2). html (); Methods to invoke the JQuery object
$ ("div"). Get (2). innerHTML; Method properties that call the DOM
4, the same function to implement set and get
This is true of many of the methods in jquery, including the following:
$ ("#msg"). html (); Returns the HTML content of an element node with the ID MSG.
To write "new content" as an HTML string to the element node content with the ID msg, the page displays bold new content
$ ("#msg"). Text (); Returns the textual content of the element node with the ID MSG.
Writes "New content" as an ordinary text string to the element Node ID msg, the page displays the new content
$ ("#msg"). Height (); Returns the height of an element with the ID msg
$ ("#msg"). Height ("300′"); Set the height of the element with ID msg to 300
$ ("#msg"). width (); Returns the width of an element with the ID msg
$ ("#msg"). Width ("300′"); Set the width of the element with ID msg to 300
$ ("input"). Val ("); Returns the value of the form's input box
$ ("input"). Val ("Test"); Set the value value of the form input box to test
$ ("#msg"). Click (); Click event that triggers the element with the ID msg
$ ("#msg"). Click (FN); Click event Add function for element with ID msg
The same Blur,focus,select,submit event can have two methods of calling

Home 1 2 3 4 last page

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.