Common face questions of jquery

Source: Internet
Author: User
Tags dashed line jquery cdn

Question: What does jquery's dollar sign $ do?

Answer: Actually the dollar sign $ is just the "jquery" Alias, it is the jquery selector, the following code:

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

Of course you can also use jquery instead of $, the following 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.

Question: 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.

Question: 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.

Question: 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:

<language=type="Text/javascript" >  $ ("*"). CSS ("2px dotted Red");   </script>     
Question: What should I do when the jquery file on the CDN is not available?

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:

<type=language=src="Http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.4.1.min.js" >  </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>           
Question: How do I use jquery to implement a click button to pop up a dialog box?

Answer: The code is as follows:

Html:

Id= "Inputfield" type="text" size="/>   "

Jquery:

<type="Text/javascript" > $ (document). Ready (function () {$ (' #Button1 '). Click (function () {alert ($ (' #inputField '). attr (</script>    
Question: What is the function of the delegate () function in jquery?

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

1. If you have a parent element that needs to add an event to the child element under it, then you can use Delegate () and the code is as follows:

$ ("UL"). Delegate (function () {$ (this). Hide ();});   

2, when the element is not available in the current page, you can use Delegate ()

Question: How do I encode and decode URLs in jquery?

Answer: In jquery, we can encode and decode URLs using the following methods.

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

Answer: The implementation code is as follows:

<type=language="JavaScript" >$ (document). Ready (  Window.history.forward (window.history.forward (-1);}); </script>          

Common face questions of jquery

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.