It's the next graduation season.
In the job search army, programmers and programmers in the IT industry are one of the hot choices of engineering college students. Especially in recent years, the Web is in full swing, attracting thousands of programmers to pursue their dreams, this article is based on the Web interviewer's experience, hoping to help you.
What is jQuery? JQuery is a reusable javascript library written in JavaScript.
The JavaScript code for setting UI text without JQuery is as follows:
- document.getElementById("txt1").value = "hello";
The JavaScript code after using the JQuery class library is as follows:
- $("#txt1").val("Hello");
IT can be seen that the JavaScript code after using the JQuery class library is much simpler and more in line with the IT industry features: Short, flat, and fast.
Will jquery replace JavaScript in the relationship between JQuery and JavaScript?
JavaScript: the most popular Web scripting language.
JQuery: an excellent Javascript framework. It is a lightweight js library, compatible with CSS3, and compatible with various Browser IE 6.0 +, FF 1.5 +, Safari 2.0 +, and Opera 9.0 + ).
Therefore, jQuery is not the JavaScript to be replaced; using JQuery makes Web development simple.
How to Use the jQuery library?
The latest jquery version V1.11.1 or V2.1.1 of the JQuery. js file downloaded from jquery.com ). JQuery file rules such as "jquery-1.4.1.j s" where 1.4.1 is the version number of the JS file.
Before developing a Web program, you must include the following JavaScript code:
- <script src="file:///C:/jquery-1.11.1.min.js" type="text/javascript"></script>
What is CDN content delivery network?
One of the most important issues during Web page development is the response of pages on the client computer: The shorter the time, the better the user experience.
One of the key factors restricting user experience is the size of Web files downloaded by browsers, including *. html, images, *. js, *. css, and other files.
To maximize reuse and save bandwidth, CDN came into being: the basic idea is to avoid bottlenecks and links that may affect data transmission speed and stability on the Internet as much as possible, make content transmission faster and more stable. The aim is to allow users to obtain the desired content nearby, solve the problem of Internet congestion, and improve the response speed when users access the website.
How to Use JQuery CDN?
We recommend that you use the official CDN node. The Code is as follows:
- <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
- <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
JQuery CDN provided by Google:
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
- </script>
Microsoft also provides JQuery CDN nodes:
- <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js">
- </script>
How does one automatically access the JQuery file of a website when the CDN network is unavailable?
Generally, CDN nodes are reliable.
But occasionally, in order to provide double insurance, you can determine that the network fails to load CDN, then the JQuery
The sample code is as follows:
- <script type="text/javascript" src="http:/ajax.microsoft.com/ajax/jquery/jquery-1.9.1.min.js"></script>
- <script type="text/javascript">if (typeof jQuery == 'undefined')
- {
- document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));
- }</script>
What is the difference between JQuery. js files of the same version and JQuery. min. js?
Same:
These two files provide the same jQuery function, that is, there is no difference in function calling.
Different:
JQuery. js files are suitable for programmers to read, as shown in:
The JQuery. min. js file compresses and deletes all spaces to save bandwidth and space and make the file smaller. It is used for network transmission and is not suitable for programmers to read.
When Will jquery. js and jquery. min. js be used?
Development and debugging scenarios: Use the JQuery. js file, because you want to debug, You can see javascript code.
Production deployment environment: Using JQuery. min. js files can reduce network width and speed up webpage loading.
What is the JQuery. vsdoc. js file?
*. Vsdoc. js files are used in Microsoft's Development Environment Visual Studio to facilitate JQuery's smart awareness. After you enter JQuery correspondence, the function type, function usage instructions, and function parameters are automatically displayed.
If JQuery is used to develop a Web program in VS, The vsdoc. js file will greatly improve the development efficiency.
How do I explain JQuery's basic syntax?
The syntax structure of jQuery can be divided into four parts:
-
By default, all Jquery commands start with a "$" symbol.
-
The second is the selection of HTML elements. For example, we select an HTML text box through ID "txt1.
-
Separated by vertices. The operator will separate the element and the action (function) of the element ).
-
The final function (action ).
For example, in the following jQuery code, the text value we are setting is "Hello world, jQuery ".
In jQuery, what is the "$" symbol?
In JQuery, the "$" symbol is a jQuery alias. The default JQuery class library starts with $.
Why JQuery. noConflict)
There are many class libraries similar to JQuery, such as MooTools, Backbone, Sammy, Cappuccino, and Knockout. Some of these class libraries also use the $ symbol. If they are used at the same time, a name conflict occurs.
JQuery. noConflict () is required to solve this conflict, so that the default symbol $ is not needed.
For example:
- $.noConflict();
- jQuery("p").text("I am jquery and I am working…");
Or use an alias instead:
- var jq = $.noConflict();
- jq("p").text("I am invoked using jquery shortcut…");
Example: JQuery Selector
Select all HTML p elements and hide them.
- $("p").hide();
Select the HTML element whose ID is Text1 and assign a value
- $("#Text1").val("Hello");
Select the Class as the Text1dHTML element and assign a value to it.
- $(".Text1").val("Hello");
In JQuery, how does one use document. ready?
After a complete html dom loading is completed, the HTML "document. ready" event is triggered. To access HTML elements through JQuery, the HTML element loading of the page is required.
For example:
- <Script>
- $ ("# Text1"). val ("Sometext"); // error. Because text1 is not loaded yet, it cannot be accessed </script>
- </Head>
- <Body>
- <Input type = "text" id = "text1"/>
- </Body>
The following is an example of an accessible HTML element in a Ready event:
- <script>
- $(document).ready(function(){
- $("#text1").val("Sometext");
- });</script>
Can I load multiple document. ready events on the same page?
Yes.
How to Use JQuery to add HTML element events?
The following two examples are used to illustrate
Example 1: select all button elements and toggle all p elements in the click event.
- $("button").click(function(){
- $("p").toggle();
- });
Example 2: select the element whose ID is p1 and perform alert in the mouseenter event.
- $("#p1").mouseenter(function(){
- alert("You entered p1!");
- });
How to Use JQuery to add a style )?
Example:
- $("li").filter(".middle").addClass("selected");
The css style content is as follows:
- <style>
- .selected { color:red; }</style>
Blog: http://powertoolsteam.blog.51cto.com/2369428/1428180