Home  >  Article  >  Web Front-end  >  How to introduce js into bootstrap

How to introduce js into bootstrap

下次还敢
下次还敢Original
2024-04-05 02:42:16893browse

The ways to introduce Bootstrap JS include: through CDN (bootstrap.bundle.min.js is recommended); downloading related files from local; installing through npm and introducing related modules.

How to introduce js into bootstrap

Bootstrap How to introduce JS

To introduce Bootstrap JS, there are the following methods:

Method 1: Use CDN

<code class="html"><script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script></code>

Method 2: Download from local

  1. Download the Bootstrap library.
  2. Add the bootstrap.js file to your project.

Method 3: Through npm

<code class="shell">npm install bootstrap</code>

Then introduce in your code:

<code class="js">import * as bootstrap from 'bootstrap';</code>

Instructions:

  • Make sure to use the JS version that matches the Bootstrap CSS version.
  • For Bootstrap 5, it is recommended to use bootstrap.bundle.min.js, which contains all JavaScript components.
  • For older versions of Bootstrap, you may need to introduce the JS files of each component separately.

Using JS components

After introducing Bootstrap JS, you can use its JavaScript components. For example:

  • Pop-up box (Modals): $('#myModal').modal()
  • Tabs (Tabs): $ ('#myTabs').tab()
  • Slider (Carousel): $('#myCarousel').carousel()

See the Bootstrap documentation for more information on specific components.

The above is the detailed content of How to introduce js into bootstrap. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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