Table of Contents
1. Have you seen the source code of JQuery? Can you give a brief overview of its implementation principle?
2. What object does this return from the init method of jQuery.fn refer to? Why return this?
3. How to use jquery Convert array to json string and then back again?
4. What is the implementation principle of jQuery’s attribute copy (extend) and how to implement it Deep copy?
①、$.extend shallow copy in jQuery
②、$.extend deep copy in jQuery
5. What is the difference between jquery.extend and jquery.fn.extend?
①, jQuery.extend(object);
②、jQuery.fn.extend( object);
③、Difference
6. How is jQuery’s queue implemented? Where can queues be used?
7. Let’s talk about the functions in Jquery What are the differences between bind(), live(), delegate() and on()?
8、JQuery一个对象可以同时绑定多个事件,这是如何实现的?
9、针对jQuery性能的优化方法?
10、Jquery与jQuery UI 有啥区别?
11、jQuery和Zepto的区别?各自的使用场景?
①、tap事件
②、Swipe事件
12、Zepto的点透问题如何解决?
①、“点透”是什么
②、点透的解决方法:
13、移动端最小触控区域是多大?
14、jQuery 的slideUp动画,如果目标元素是被外部事件驱动, 当鼠标快速地连续触发外部元素事件, 动画会滞后的反复执行,该如何处理呢?
15、移动端的点击事件的有延迟,时间是多久,为什么会有?怎么解决这个延时?
16、你从jQuery学到了什么?
17、请指出.get(),[],eq() 的区别。
18、请指出$ 和$.fn 的区别,或者说出$.fn 的用途。
19、jQuery取到的元素和原生Js取到的元素有什么区别
20、原生JS的window.onload与Jquery的$(document).ready(function(){})有什么不同?如何用原生JS实现Jq的ready方法?
①、window.onload()
②、$(document).ready()
Home Web Front-end JS Tutorial Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs)

Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs)

Feb 14, 2022 am 10:31 AM
jquery Front-end interview

This article summarizes some front-end interviews based on jQuery to share with you. It contains common interview questions about jQuery and common mobile questions. I hope it will be helpful to everyone!

Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs)

Related recommendations: 2022 Big Front-End Interview Questions Summary (Collection)

jQuery front-end interview - including mobile terminal FAQ

1. Have you seen the source code of JQuery? Can you give a brief overview of its implementation principle?

jquery source code is encapsulated in a self-execution environment of an anonymous function, which helps to prevent global pollution of variables. Then by passing in the window object parameters, the window object can be used as a local variable. , the advantage is that when accessing the window object in jquery, there is no need to return the scope chain to the top-level scope, so that the window object can be accessed faster. Similarly, passing in the undefined parameter can shorten the scope chain when looking for undefined. [Recommended learning: jQuery video tutorial]

    (function( window, undefined ) {
         //用一个函数域包起来,就是所谓的沙箱
         //在这里边var定义的变量,属于这个函数域内的局部变量,避免污染全局
         //把当前沙箱需要的外部变量通过函数参数引入进来
         //只要保证参数对内提供的接口的一致性,你还可以随意替换传进来的这个参数
        window.jQuery = window.$ = jQuery;
    })( window );
Copy after login
  • jquery encapsulates some prototype properties and methods in jquery.prototype. In order to shorten the name, it is assigned to jquery.fn, this is a very vivid way of writing.
  • There are some array or object methods that are often used. jQuery saves them as local variables to improve access speed.
  • The chain call implemented by jquery can save code, and the same object is returned, which can improve code efficiency.
  • The advantage of jquery is chain operations and implicit iteration

2. What object does this return from the init method of jQuery.fn refer to? Why return this?

The returned this refers to the jquery object after the current operation. In order to realize the chain operation of jquery

3. How to use jquery Convert array to json string and then back again?

Use jquery global method $.parseJSON this method

4. What is the implementation principle of jQuery’s attribute copy (extend) and how to implement it Deep copy?

①、$.extend shallow copy in jQuery

$.extend shallow copy in jQuery, when copying object A, object B will copy all fields of A , if the field is a memory address, B will copy the address, if the field is a primitive type, B will copy its value. Its disadvantage is that if you change the memory address pointed by object B, you also change the field of object A pointing to this address.

$.extend(a,b)
Copy after login
②、$.extend deep copy in jQuery

$.extend deep copy in jQuery. This method will completely copy all the data. The advantage is B There is no mutual dependence on A (A and B are completely disconnected). The disadvantage is that the copy speed is slower and the cost is higher.

$.extend(true,a,b)
Copy after login

5. What is the difference between jquery.extend and jquery.fn.extend?

①, jQuery.extend(object);
  • It is to add a class method to the jQuery class, which can be understood as adding a static method. For example:
jQuery.extend({
   min: function(a, b) { return a < b ? a : b; },
   max: function(a, b) { return a > b ? a : b;
});
jQuery.min(2,3); //  2
jQuery.max(4,5); //  5
Copy after login
  • jQuery.extend(target, object1, [objectN])Extend an object with one or more other objects and return the extended object .
var settings = { validate: false, limit: 5, name: "foo" };
var options = { validate: true, name: "bar" };
jQuery.extend(settings, options);
Copy after login
  • Result: settings == { validate: true, limit: 5, name: “bar” }
②、jQuery.fn.extend( object);
  • #$.fn?
  • $.fn refers to the namespace of jQuery. The members on fn (method function and attribute property) will affect the jQuery instance Every one works.
  • Looking at the jQuery code, it is not difficult to find.
jQuery.fn = jQuery.prototype = {
    init: function( selector, context ) {//.... 
};
Copy after login
  • OriginaljQuery.fn = jQuery.prototype
  • So, it is an extension of jQuery.prototype, which is to add " member function". Instances of the jQuery class can use this "member function".
③、Difference
  • jQuery.fn.extend(object); extends jQuery object method
  • jQuery.extend extends jQuery global method

6. How is jQuery’s queue implemented? Where can queues be used?

In the core of jQuery, there is a set of queue control methods. This set of methods consists of three methods: queue()/dequeue()/clearQueue(). It needs to be executed continuously and sequentially. The control of the function can be said to be concise and comfortable. It is mainly used in the animate () method, ajax and other events that need to be executed in chronological order.

var _slideFun = [
function() {
$(&#39;.one&#39;).delay(500).animate({
top: &#39;+=270px&#39;
},500, _takeOne);
},
function() {
$(&#39;.two&#39;).delay(300).animate({
top: &#39;+=270px&#39;
},500, _takeOne);
}
];
$(&#39;#demo&#39;).queue(&#39;slideList&#39;, _slideFun);
var _takeOne = function() {
$(&#39;#demo&#39;).dequeue(&#39;slideList&#39;);
};
_takeOne();
Copy after login

7. Let’s talk about the functions in Jquery What are the differences between bind(), live(), delegate() and on()?

bind(), live(), and delegate() in jquery are all implemented based on on

encapsulates a compatible event binding method that binds one or more events to the event processing function on the selected element Bind event handlers for specific events of each matching elementAppend an event handler to all matching elements, even if the element is added laterAdd one or more event handlers to the specified element (a child element of the selected element) and specify the function to run when these events occur
MethodDescription
##on
bind(type,[ data],fn)
live(type,[data], fn)
delegate(selector, [type],[data],fn)
Difference:

.bind() is directly bound to the element

MethodDescription is directly bound Set on the element is bound to the element through bubbling. More suitable for list types, bound to document DOM nodes. The advantage of .bind() is that it supports dynamic data is a more accurate small-scale use of event agents. The performance is better than .live() is the latest version 1.9 that integrates the previous three methods. Event binding mechanism

8、JQuery一个对象可以同时绑定多个事件,这是如何实现的?

jquery中事件绑定的函数中传递多个事件参数,执行事件的时候判断执行事件的类型

9、针对jQuery性能的优化方法?

  • 基于Class的选择性的性能相对于Id选择器开销很大,因为需遍历所有DOM元素。

  • 频繁操作的DOM,先缓存起来再操作。用Jquery的链式调用更好。
    比如:

var str=$("a").attr("href");
for (var i = size; i < arr.length; i++) {}
Copy after login
  • for 循环每一次循环都查找了数组(arr) 的.length 属性,在开始循环的时候设置一个变量来存储这个数字,可以让循环跑得更快:
for (var i = size, length = arr.length; i < length; i++) {}
Copy after login

10、Jquery与jQuery UI 有啥区别?

  1. jQuery是一个js库,主要提供的功能是选择器,属性修改和事件绑定等等。
  2. jQuery UI则是在jQuery的基础上,利用jQuery的扩展性,设计的插件。提供了一些常用的界面元素,诸如对话框、拖动行为、改变大小行为等等。
  3. jQuery本身注重于后台,没有漂亮的界面,而jQuery UI则补充了前者的不足,他提供了华丽的展示界面,使人更容易接受。既有强大的后台,又有华丽的前台。jQuery UI是jQuery插件,只不过专指由jQuery官方维护的UI方向的插件。

11、jQuery和Zepto的区别?各自的使用场景?

zepto主要用在移动设备上,只支持较新的浏览器,好处是代码量比较小,性能也较好。
jquery主要是兼容性好,可以跑在各种pc,移动上,好处是兼容各种浏览器,缺点是代码量大,同时考虑兼容,性能也不够好。

zepto和jQuery选择器实现方法不一样,jQuery使用正则,zepto是使用querySelectAll
zepto针对移动端程序,Zepto还有一些基本的触摸事件可以用来做触摸屏交互,如:

①、tap事件

tap,singleTap,doubleTap,longTap

②、Swipe事件

swipe,swipeLeft,swipeRight,swipeUp,swipeDown

12、Zepto的点透问题如何解决?

①、“点透”是什么

你可能碰到过在列表页面上创建一个弹出层,弹出层有个关闭的按钮,你点了这个按钮关闭弹出层后后,这个按钮正下方的内容也会执行点击事件(或打开链接)。这个被定义为这是一个“点透”现象。

②、点透的解决方法:
  • 方案一:来得很直接github上有个fastclick可以完美解决

https://github.com/ftlabs/fastclick,引入fastclick.js,因为fastclick源码不依赖其他库所以你可以在原生的js前直接加上

   window.addEventListener( "load", function() {
        FastClick.attach( document.body );
    }, false );
Copy after login
  • 方案二:用touchend代替tap事件并阻止掉touchend的默认行为preventDefault()

  • 方案三:延迟一定的时间(300ms+)来处理事件

13、移动端最小触控区域是多大?

移动端最小触控区域44*44px ,再小就容易点击不到或者误点

14、jQuery 的slideUp动画,如果目标元素是被外部事件驱动, 当鼠标快速地连续触发外部元素事件, 动画会滞后的反复执行,该如何处理呢?

每次动画开始的时候先使用stop()函数停止当前未动完的动画

15、移动端的点击事件的有延迟,时间是多久,为什么会有?怎么解决这个延时?

click 有300ms 延迟,为了实现safari的双击事件的设计,浏览器要知道你是不是要双击操作。

16、你从jQuery学到了什么?

首先明白了封装的好处,
链式操作的原理
闭包的好处

17、请指出.get(),[],eq() 的区别。

.bind()
.live()
.delegate()
.on()
方法说明
.get是jquery中将jquery对象转换为原生对象的方法
[]是采用了获取数组值的方式将jquery对象转换为原生对象的方法
eq()是获取对象列表中的某一个jquery dom对象

18、请指出$ 和$.fn 的区别,或者说出$.fn 的用途。

$代表的是jquery对象
$.fn是代表的jQuery.prototype
$.fn是用来给jquery对象扩展方法的

19、jQuery取到的元素和原生Js取到的元素有什么区别

jQuery取到的元素是包含原生dom对象,和jQuery扩展的方法

20、原生JS的window.onload与Jquery的$(document).ready(function(){})有什么不同?如何用原生JS实现Jq的ready方法?

①、window.onload()

window.onload()方法是必须等到页面内包括图片的所有元素加载完毕后才能执行。

②、$(document).ready()

$(document).ready()是DOM结构绘制完毕后就执行,不必等到加载完毕。

function ready(fn){
if(document.addEventListener) {        //标准浏览器
document.addEventListener(&#39;DOMContentLoaded&#39;, function() {
//注销事件, 避免反复触发
document.removeEventListener(&#39;DOMContentLoaded&#39;,arguments.callee, false);
fn();            //执行函数
}, false);
}else if(document.attachEvent) {        //IE
document.attachEvent(&#39;onreadystatechange&#39;, function() {
if(document.readyState == &#39;complete&#39;) {
document.detachEvent(&#39;onreadystatechange&#39;, arguments.callee);
fn();        //函数执行
}
});
}
};
Copy after login

(学习视频分享:web前端教程

The above is the detailed content of Summarize and share some jQuery-based front-end interviews (including mobile terminal FAQs). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: &lt

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ​​the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

Introduction to how to add new rows to a table using jQuery Introduction to how to add new rows to a table using jQuery Feb 29, 2024 am 08:12 AM

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:

See all articles