bootstrap5 .jqurey报错Cannot read properties of null (reading 'show')

发布时间 2023-04-06 13:42:27作者: 嬉戏_人间
// to enable tooltips with the default configuration
$('[data-bs-toggle="tooltip"]').tooltip()

// to initialize tooltips with given configuration
$('[data-bs-toggle="tooltip"]').tooltip({
  boundary: 'clippingParents',
  customClass: 'myClass'
})

// to trigger the `show` method
$('#myTooltip').tooltip('show')

Optionally using jQuery 

You don’t need jQuery in Bootstrap 5, but it’s still possible to use our components with jQuery. If Bootstrap detects in the object, it’ll add all of our components in jQuery’s plugin system. This allows you to do the following:jQuerywindow

推荐使用原生js,需要使用jQuery时需要按上面代码中的方式调用

官方文档:JavaScript · Bootstrap v5 中文文档 v5.3 | Bootstrap 中文网 (bootcss.com)