JavaScript and Ajax sections (4)

Source: Internet
Author: User
Tags prev

31. What is JQuery Selector Selector

1) The jquery selector inherits part of the syntax of the CSS and path language, allowing for quick and accurate selection of DOM elements through tag names, property names, or content, without worrying about browser compatibility, precise positioning of elements of the page via the jquery selector, To complete the processing of element properties and behaviors.

Selectors are the foundation of jquery, where event handling of objects, traversal of DOM, and AJAX operations all depend on selectors

2) Advantages of jquery selector:

A concise notation

A perfect event handling mechanism

Supports CSS1 to CSS3 selectors

32. JQuery Selector SelectorTypes of

1). Basic Selector

The basic selector is the most common selector in jquery and the simplest selector, which finds DOM elements through element Id,class and tag names

2). Hierarchy Selector

If you want to get specific elements through a hierarchical relationship between DOM elements, you need to use a hierarchy selector

3). Filter Selector

Filter selector is mainly through the specific filtering rules to filter out the required Dom elements, the selector is ":" Beginning, filter selector and the following several

4). form selector

The form selector is primarily filtered by the selected form element

5). Property Selector

The filter rule for a property filter selector is to get the corresponding element through the attributes of the element

7). Content Filter Selector

The filtering rules of the Content filter selector are mainly embodied in the sub-elements and the text content that it contains.

8). Visibility Filter Selector

The Visibility filter selector selects the appropriate element based on the visible and invisible state of the element

33. is there a difference between a selector in jquery and a selector in CSS?

A :the jquery selector supports selectors in CSS, and the jquery selector can be used to add styles and add appropriate styles to the selectors in the CSS.

34. is the siblings () method the same as the $ (' prev~div ') selector?

A : $ (' prev~div ') can only select the peers <div> elements behind the ' #prev ' element and the siblings () method is independent of the position before and after, as long as the sibling nodes are matched.

35. What is the difference between hover () and toggle () in jquery?

A : both hover () and toggle () are two synthetic events in jquery.

The hover () method simulates a cursor hover event.

The toggle () method is a continuous click event.

36. $ ("#msg"). Text () and $ ("#msg"). What is the difference between text ("<b>new content</b>")?
$ ("#msg"). HTML () and $ ("#msg"). What is the difference between HTML ("<b>new content</b>")?

A :$ ("#msg"). Text () is the textual content of the element node that returns the ID MSG

$ ("#msg"). Text ("<b>new content</b>"); is to write "<b>new content</b>" as a normal text string in the element node content with ID msg, the page directly displays "<b>new content</b>", text () Method is valid for both HTML and XML documents

$ ("#msg"). HTML () is the HTML content of the element node that gets the ID msg. This function cannot be used with XML documents. But can be used in XHTML documents

$ ("#msg"). HTML ("<b>new content</b>"), which writes "<b>new content</b>" as HTML content to the element node content of the ID msg. The page displays the bold "newcontent" directly .

37. the difference between a jquery object and a DOM object

jquery objects can invoke methods that are unique to jquery. For example, methods such as jqueryobj.html (), Jqueryobj.val (), and cannot use properties and methods specific to DOM objects, such as domobj.value,domobj.innerhtml.

jquery objects can be transformed from DOM objects to each other

38. How are jquery objects and Dom objects converted?

1.jquery to Dom object :

1) JQuery object is an array object, you can get the corresponding DOM object by [index], for example, the page has a Div object with ID mydiv, can use var domobj = $ ("#myDiv") [0] This way to get the DOM object that the div corresponds to

2) get the corresponding Dom object by get (index), var domobj = $ ("#myDiv"). Get (0);

2.DOM object to jquery object:

use the $ (DOM object) directly to convert the sample code:

var domobj = document.getElementById ("mydiv");

var jqueryobj = $ (domobj);

$ () is equivalent to the constructor of a jquery object

39. How do you use ajax in jquery?

A: If it is a regular Ajax program, use $.load (), $.get (), $.post (), it can be done,

generally I will use the $.get () method.

If you need to set beforesend (pre-commit callback function), error (post-failure processing), success (post-success processing)

and complete (post-request processing) callback function, etc., this time I will use $.ajax ()

40. is there a difference between $.get () submission and $.post () submission in jquery?

1) The $.get () method uses the Get method to make an asynchronous request, and the $.post () method uses the Post method to make an asynchronous request.

2) The GET request passes the parameter after the URL, and the POST request is sent to the Web server as the entity body content of the HTTP message, which is not visible to the user.

3) The size of the data transferred by the Get mode cannot exceed 2KB and the post is much larger.

4) The data requested by the Get method is cached by the browser, so there is a security issue.

JavaScript and Ajax sections (4)

Related Article

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.