jquery Selection Questions and Answers

Source: Internet
Author: User
Tags dashed line jquery cdn

1. What is the role of jquery dollar sign $?
Answer: Actually the dollar sign $ is just the "jquery" Alias, it is the jquery selector, the following code:

HTML code
$ (document). Ready (function () {});

Of course you can also use jquery instead of $, the following code:

HTML code
JQuery (document). Ready (function () {});
jquery is the use of this dollar symbol to achieve a variety of flexible DOM element selection, such as $ ("#main") is the ID of the element is selected.

--------------------------------------------------I'm a split line--------------------------------------------------------------

2. What is the difference between the onload () function in the body and Document.ready () in jquery?

Answer: The difference between onload () and Document.ready () has the following two points:

1. We can use multiple document.ready () in the page, but only one time, onload ().
2. The Document.ready () function is called after the page DOM element has been loaded, and the onload () function is called after all associated resources (including images, audio) have been loaded.

--------------------------------------------------I'm a split line--------------------------------------------------------------

3. What kinds of selectors are there in jquery?

Answer: From my own point of view, there can be 3 types of selectors, as follows:

1. Basic selector: Returns the matching DOM element directly from the ID, CSS class name, and element name.
2, hierarchical selector: Also known as the path selector, you can select the corresponding DOM element according to the path hierarchy.
3. Filter selector: Filter the relevant conditions on the previous basis to get the matching DOM elements.

--------------------------------------------------I'm a split line--------------------------------------------------------------

4. Use jquery to set all the element borders on the page to a 2px wide dashed line?

Answer: This is the time for the jquery selector to play, the code is as follows:

HTML code
<script language= "javascript" type= "Text/javascript" >
$ ("*"). CSS ("Border", "2px dotted Red");
</script>

--------------------------------------------------I'm a split line--------------------------------------------------------------

5, when the jquery file on the CDN is not available, what should I do?

Answer: To conserve bandwidth and the stability of script references, we use jquery files on the CDN, such as Google's jquery CDN service. However, if the jquery service on these cdns is not available, we can also switch to the jquery version of the local server by using the following code:
HTML code
<script type= "Text/javascript" language= "JavaScript" src= "http://ajax.aspnetcdn.com/ajax/jquery/ Jquery-1.4.1.min.js "></script>

<script type=*text/javascript*>//<! [cdata[

if (typeof jQuery = = *undefined*) {
document.write (unescape ("%3cscript src=*/script/jquery-1.4.1.min.js* type=*text/javascript*%3E%3C/script%3E"));
}//]]>

</script>

--------------------------------------------------I'm a split line--------------------------------------------------------------

6, how to use jquery implementation Click Button Pop up a dialog box?

Answer: The code is as follows:

HTML code
<input id= "Inputfield" type= "text" size= "/>"

Jquery:
<script type= "Text/javascript" > $ (document). Ready (function () {$ (* #Button1 *). Click (function () {alert ($ (*# inputfield*). attr ("value")); }); }); </script>

--------------------------------------------------I'm a split line--------------------------------------------------------------

7. What is the function of delegate () in jquery?

Answer: Delegate () will be used in the following two cases:

(1), if you have a parent element, you need to add an event to the child element under it, then you can use Delegate (), the code is as follows:
HTML code
$ ("ul"). Delegate ("Li", "click", Function () {
$ (this). Hide ();
});
(2), when the element is not available in the current page, you can use Delegate ()

--------------------------------------------------I'm a split line--------------------------------------------------------------

8. How to encode and decode URLs with jquery?

Answer: In jquery, we can encode and decode URLs using the following methods.
encodeURIComponent (URL) and decodeuricomponent (URL)

Question: How do I disable the browser's forward back button with jquery?

Answer: The implementation code is as follows:
HTML code
<script type= "Text/javascript" language= "JavaScript" >
$ (document). Ready (function () {
Window.history.forward (1);
OR
Window.history.forward (-1);
});
</script>

--------------------------------------------------I'm a split line--------------------------------------------------------------


jquery Selection Questions and Answers

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.