我的代码依赖于Bootstrap4和Popper.js。Bootstrap有一个捆绑的JS文件,其中包含Popper.js,但我不知道如何判断是加载了捆绑版本还是非捆绑版本。
如果分别包含bootstrap.js和popper.js,我可以测试是否定义了Popper,但如果包含bootstrap.bundle.js,则未定义Popper,但依赖于Popper的引导组件仍然有效。
我可以使用像typeof $().modal这样的工具来检查是否包含bootstrap,但捆绑和非捆绑版本都是如此。
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Bundle Test</title>
<!-- Load jQuery JS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="crossorigin="anonymous"></script>
<!-- Load Bootstrap Bundled JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
console.log('jQuery type is: ' + typeof $);
console.log('Bootstrap modal type is: ' + typeof $().modal);
console.log('Popper type is: ' + typeof Popper);
});
</script>
</head>
<body>
</body>
</html>在本例中,我希望Popper是一个函数,因为它包含在Bootstrap包中,但它是undefined。
发布于 2019-05-27 12:39:33
您可以尝试检查在全局空间中是否有合适的方法可用。如果它是真的,那么你就知道bootstrap.js和popper.js都是单独包含的,否则就是bootstrap.bundle.js
https://stackoverflow.com/questions/56319549
复制相似问题