后台需要学习jquery吗_您应该在2020年使用或学习jQuery吗?

随着浏览器API的标准化,jQuery的一些功能已被替代,如选择DOM元素、处理事件和AJAX请求。然而,jQuery仍被广泛使用,特别是在需要兼容旧浏览器或使用依赖jQuery的库(如Bootstrap)时。对于新项目,若目标是现代浏览器,通常不再推荐使用jQuery,但团队合作和个人技能考虑仍可能需要对其有一定了解。
摘要由CSDN通过智能技术生成

后台需要学习jquery吗

Whatever your preferences are in terms of JavaScript frameworks and libraries, jQuery has played a big part in the JavaScript ecosystem.

无论您偏爱JavaScript框架和库,jQuery在JavaScript生态系统中都发挥了重要作用。

It used to be much more popular a few years ago, and now some of the needs of jQuery have been superseded by modern browsers (luckily!), but this JavaScript library is still used by a lot of people.

几年前它曾经更加流行,现在,现代浏览器已经取代了jQuery的某些需求(幸运的是!),但是这个JavaScript库仍然被很多人使用。

Why did jQuery become so popular in the first place? First, jQuery was born in a world where JavaScript applications weren’t a thing. In the early-mid 2000s JavaScript was mainly used to power slideshows and other widgets that appeared inside a page, like image galleries, date pickers and so on. It wasn’t powerful enough to do a lot of things without being too slow (computers were slower too, of course).

为什么jQuery首先变得如此流行? 首先,jQuery诞生于一个JavaScript应用不是万物的世界。 在2000年代中期,JavaScript主要用于增强幻灯片和其他出现在页面内的小部件的功能,例如图像库,日期选择器等。 它没有足够强大的功能来执行很多事情而又不会太慢(当然,计算机也要慢一些)。

It should be noted that jQuery was not the only or the first library. Other ones were very popular at the time, like Mootools, YUI, Dojo Toolkit, Scriptaculous and Prototype. jQuery probably became the most famous of those, later on.

应当指出,jQuery不是唯一的库,也不是第一个库。 其他工具当时非常受欢迎,例如Mootools,YUI,Dojo Toolkit,Scriptaculous和Prototype。 后来,jQuery可能成为其中最著名的。

Browsers at the time had a lot of interoperability issues. We had lots of cross-browser quirks and standardization issues, and jQuery helped us by creating an abstraction layer and taking care of al the workarounds.

当时的浏览器存在很多互操作性问题。 我们有很多跨浏览器的怪癖和标准化问题,而jQuery通过创建抽象层并解决所有变通办法来帮助我们。

jQuery allowed you to select DOM elements using the CSS selectors syntax, it was very user friendly and very simple to extend. It made JavaScript animations simple.

jQuery允许您使用CSS选择器语法选择DOM元素,它非常用户友好并且扩展非常简单。 它使JavaScript动画变得简单。

It also helped simplify working with AJAX (and its cross-browser differences) at a time when this term was super popular, and this also gave jQuery a nice boost in term of popularity.

在这个术语非常流行时,它还有助于简化使用AJAX(及其跨浏览器的区别)的工作,这也使jQuery在受欢迎程度方面得到了很好的提升。

Today, we don’t have a lot of browser compatibility issues, and the Selectors API and Fetch standardized to the browser two of the best features of jQuery.

今天,我们没有太多的浏览器兼容性问题,并且Selectors APIFetch标准化了浏览器的jQuery的两个最佳功能。

jQuery is certainly a topic full of debate. Some people say jQuery is a relic of the past, some people still use it day to day. Some people spend their time writing about why we don’t need jQuery.

jQuery当然是一个充满争议的话题。 有人说jQuery是过去的遗物,有些人仍然每天都在使用它。 有些人花时间写为什么我们不需要jQuery

It’s surely declining in usage in the past few years:

在过去几年中,它的使用率肯定会下降:

jQuery trends

Today the JavaScript landscape has dramatically changed. That said, it’s still useful to know what jQuery can do for you.

今天,JavaScript格局发生了巨大变化。 也就是说,了解jQuery可以为您做什么仍然很有用。

我们为此使用jQuery的东西现在有了标准化的浏览器API (Things we used jQuery for that now have a standardized browser API)

选择DOM元素 (Selecting DOM elements)

The jQuery way:

jQuery方式:

$('.button')

We can now use the Selectors API:

现在,我们可以使用Selectors API:

document.querySelector('.button')

if you have more elements:

如果您有更多元素:

document.querySelectorAll('.button')

等待DOM加载 (Wait for the DOM to be loaded)

The jQuery way:

jQuery方式:

$(document).ready(() => {
	 //...
})

The DOM way:

DOM方式:

document.addEventListener("DOMContentLoaded", () => {
  //...
})

从DOM元素添加或删除类 (Add or remove classes from a DOM element)

The jQuery way:

jQuery方式:

el.addClass('big')
el.removeClass('big')
el.toggleClass('big')

The DOM way:

DOM方式:

el.classList.add('big')
el.classList.remove('big')
el.classList.toggle('big')

从DOM中删除元素 (Removing an element from the DOM)

The jQuery way:

jQuery方式:

el.remove()

The DOM way:

DOM方式:

el.remove()

(right, no change)

(没错,没变化)

更改DOM中元素的内容 (Change the content of an element in the DOM)

The jQuery way:

jQuery方式:

el.text('Hello')
el.html('Hello')
el.text()
el.html()

The DOM way:

DOM方式:

el.innerHTML = 'Hello'
el.textContent = 'Hello'
el.innerHTML
el.textContent

在DOM中选择父元素 (Selecting the parent element in the DOM)

The jQuery way:

jQuery方式:

el.parent()

The DOM way:

DOM方式:

el.parentNode

侦听有关DOM元素的事件 (Listening for events on DOM elements)

The jQuery way:

jQuery方式:

el.on('click', (e) => { /* ... */ })

The DOM way:

DOM方式:

el.addEventListener('click', (e) => { /* ... */ })

AJAX请求 (AJAX requests)

The jQuery way:

jQuery方式:

$.ajax({
  url: '/api.json',
  type: 'GET'
  success: (data) => {
    console.log(data)
  }
})

The modern JS way:

现代JS方式:

fetch('/api.json')
  .then(response => response.text())
  .then(body => console.log(body))

动画制作 (Animations)

jQuery animations can now be done in the browser using CSS Transitions or CSS Animations.

现在,可以使用CSS Transitions或CSS Animations在浏览器中完成jQuery动画。

浏览器怪癖 (Browser quirks)

Transpile your code using Babel, or use specific polyfills (polyfill.io)

使用Babel转换代码,或使用特定的polyfills( polyfill.io )

您今天应该使用jQuery吗? (Should you use jQuery today?)

Let’s answer the question that this article poses in its title. If you don’t already know jQuery, is it worth learning it now?

让我们回答本文标题中提出的问题。 如果您还不了解jQuery,现在值得学习吗?

In my opinion jQuery should not be used any more in new projects that only target modern browsers, and of course if your project relies on it for some particular reason, or just because you use plugins or other code that needs jQuery, definitely keep using it.

在我看来,不应在仅针对现代浏览器的新项目中再使用jQuery,当然,如果您的项目出于某些特定原因而依赖它,或者仅仅是因为您使用了需要jQuery的插件或其他代码,则一定要继续使用它。

Some libraries also have a dependency on jQuery, like Bootstrap. You might also buy ready-made templates that just use it and its plugins.

一些库也依赖jQuery,例如Bootstrap。 您可能还购买了仅使用它及其插件的现成模板。

Maybe you work in a team where frontend developers are not all JavaScript wizards and they are more used to jQuery than with newer standards. If this gets the job done, that’s cool.

也许您是在一个团队中工作的,其中前端开发人员并不全是JavaScript向导,并且他们比使用新标准更习惯jQuery。 如果这能完成工作,那就太好了。

You might also not have the luxury of use the latest cool tech (like React or Vue) because you are required to support old browsers, that have an older set of standards. In this case, jQuery is still hugely relevant for you.

您可能还没有奢侈地使用最新的炫酷技术(例如React或Vue),因为您需要支持具有旧标准的旧浏览器。 在这种情况下,jQuery与您仍然息息相关。

翻译自: https://flaviocopes.com/jquery/

后台需要学习jquery吗

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值