jquery Classic questions and answers featured [reprint]

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 sign 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 more than one document.ready () in the page, but only once 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, the basic selector: directly based on the ID, CSS class name, element name to return the matching DOM elements. 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: <script language= "JavaScript" type= "Text/javascript" > $ ("*"). CSS ("Border", "2px D otted 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. But 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: <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> question: How do I use jquery to implement a click button to pop up a dialog box? Answer: The code is as follows: Html:<input id= "Inputfield" type= "text" size= ""/>jquery:<script type= "Text/javascript" > $ ( Document). Ready (function () {$ (' #Button1 '). Click (function () {alert (' #inputField '). attr ("value"));}); </script> question: What is the function of the delegate () function in jquery? Answer: Delegate () will be used in the following two cases to: 1, if you have a parent element, you need to add an event to its sub-elements, then you can use Delegate (), the code is as follows: $ ("ul"). Delegate ("Li", "click", Function () {$ (this). Hide ();}); 2, when the element is not available in the current page, you can use the delegate () problem: How to encode and decode the URL 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: <script type= "Text/javascript" language= "JavaScript" >$ (document). Ready (function () {     Window.history.forward (1);  OR   Window.history.forward (-1);}); </script>

This article link: http://www.codeceo.com/article/jquery-interview.html
This Article code rural network – Xiao Feng

jquery Classic questions and answers featured [reprint]

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.