JQuery classic interview questions and answer selections, jquery Questions and answers
JQuery is a very popular Javascript framework. If you want to engage in Web Front-end development, jQuery is a technology that you must master and be proficient in application. This article has sorted out some classic questions and answers about jQuery and shared them with those who are about to interview Web development posts.
Q: What is the function of jQuery dollar sign $?
A: In fact, the dollar sign $ is just the alias of "jQuery". It is the jQuery selector. The code below:
$(document).ready(function(){});
Of course, you can also use jQuery to replace $, as shown in the following code:
jQuery(document).ready(function(){});
JQuery uses this dollar sign to implement various flexible DOM element selection. For example, $ ("# main") is the element with the id as main.
Q: What is the difference between the onload () function in the body and the document. ready () function in jQuery?
A: The differences between onload () and document. ready () are as follows:
1. We can use multiple documents. ready () on the page, but we can only use onload () once ().
2. document. the ready () function is called after the DOM element of the page is loaded. the onload () function is called for all associated resources (including images and audios) it is called only after loading.
Q: What types of selectors does jQuery have?
A: From my perspective, there are three types of selectors:
1. Basic selector: return the matched dom elements based on the id, css class name, and element name.
2. Level selector: it is also called a path selector. You can select the corresponding DOM element based on the path hierarchy.
3. Filter selector: Filter related conditions on the top to obtain the matched dom element.
Q: Can I use jQuery to set the border of all elements on the page to a 2px dotted line?
A: This is exactly when the jQuery selector is playing. The Code is as follows:
<script language="javascript" type="text/javascript"> $("*").css("border", "2px dotted red"); </script>
Q: What should I do if jQuery files on CDN are unavailable?
A: To save bandwidth and Stability of script reference, we will use jQuery files on CDN, such as google's jquery cdn service. However, if the jQuery service on the CDN is unavailable, we can use the following code to switch to the jQuery version of the local server:
<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>
Q: How to Use jQuery to bring up a dialog box by clicking the button?
A: The Code is as follows:
HTML:
<input id="inputField" type="text" size="12"/>
JQuery:
<script type="text/javascript"> $(document).ready(function () { $('#Button1').click(function () { alert($('#inputField').attr("value")); }); }); </script>
Q: What is the role of the Delegate () function in jQuery?
A: delegate () is used in the following two cases:
1. If you have a parent element and want to add events to its child elements, you can use delegate (). The Code is as follows:
$("ul").delegate("li", "click", function(){$(this).hide();});
2. When an element is unavailable on the current page, you can use delegate ()
Q: How to Use jQuery to encode and decode URLs?
A: In jQuery, we can use the following methods to encode and decode URLs.
encodeURIComponent(url) and decodeURIComponent(url)
Q: How can I use jQuery to disable the browser's forward and backward buttons?
A: 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>
Jquery interview questions
What is the first character of jquery1.4 dev?
I used jquery for the js script application in the interview questions. What is the jquery framework?
Jquery is a library, which is currently the second most popular among various js libraries. The first is prototype.
Mozilla has been using jquery
Its syntax is write less and do more.
The most practical experience is to make the code more refined and indeed write less, and the method for encapsulating nodes is very different.