如何使用Bootstrap 5从jQuery切换到Vanilla JavaScript

本文介绍如何在Bootstrap 5中使用Vanilla JS替代jQuery。Bootstrap 5不再依赖jQuery,提供了更小的包体积。教程涵盖如何初始化工具提示、使用Collapse方法切换元素可见性,并给出了具体的JavaScript代码示例。
摘要由CSDN通过智能技术生成

Bootstrap 5 is a free and open-source CSS framework directed at responsive, mobile-first front-end web development.

Bootstrap 5是一个免费的开源CSS框架,专门用于响应式,移动优先的前端Web开发。

In case you didn't know, Bootstrap 5 alpha has been officially launched. It has removed jQuery as a dependency, has dropped support for Internet Explorer 9 and 10, and brings some awesome updates for the Sass files, markup, and a new Utility API.

如果您不知道, Bootstrap 5 alpha已正式启动 。 它已删除了jQuery的依赖关系,放弃了对Internet Explorer 9和10的支持,并为Sass文件,标记和新的Utility API带来了一些很棒的更新。

This tutorial will show you how to start using VanillaJS instead of jQuery when building websites using the newest version of Bootstrap 5.

本教程将向您展示在使用最新版本的Bootstrap 5构建网站时如何开始使用VanillaJS而不是jQuery。

入门 (Getting started)

You will need to include Bootstrap 5 in your project. There are several ways to do this, but to keep it simple we will include the framework via CDN.

您将需要在项目中包含Bootstrap 5。 有几种方法可以做到这一点,但为简单起见,我们将通过CDN包含该框架。

First of all, let's create a blank index.html page inside a project folder:

首先,让我们在项目文件夹中创建一个空白的index.html页面:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Bootstrap 5 Vanilla JS tutorial by Themesberg</title>
</head>
<body>
    
</body>
</html>

Include the bootstrap.min.css stylesheet before the end of your <head> tag:

<head>标记的末尾包括bootstrap.min.css样式表:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css" integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I" crossorigin="anonymous">

Afterwards include the Popper.js library and the main Bootstrap JavaScript file before the end of your <body> tag:

然后在<body>标记的末尾包含Popper.js库和Bootstrap主JavaScript文件:

<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZ
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值