代码之家  ›  专栏  ›  技术社区  ›  Alexandr Sulimov

从webpack bundle.js获取/导入bootstrap.js

  •  -1
  • Alexandr Sulimov  · 技术社区  · 6 年前

    抱歉,我没有使用Webpack的经验。

    我有一个用Webpack生成的模板页。

    使用bootstrap.js显示模式对话框的页面

    bundle.js中包含的bootstrap.js

    我需要显示/隐藏/侦听模式窗口的事件,但我不能使用 $(dialog').modal(“hide”),因为没有加载引导(在当前上下文中?)

    如何导入/访问bundle.js中的bootstrap.js?

    Examples - try to close modal with button "Close with JS"
    

    Sample #1 used bootstrap.js from bundle.js

    误差

    $(…).modal不是函数

    Sample #2 used bootstrap.js from bundle.js and in html

    误差

    未删除模式背景渐变

    导入设置

    enter image description here

    1 回复  |  直到 6 年前
        1
  •  1
  •   Seyhmus Gokcen    6 年前

    我只是检查您的代码笔示例,不知何故在您的两个示例上生成了两个模式背景。(带或不带引导程序)

    enter image description here

    当另一个关闭时,其中一个仍留在页面上。

    我只是检查一下bootsrap上是否有bug或者其他什么东西,并在github上面对封闭的问题;

    https://github.com/twbs/bootstrap/issues/679

    不知何故,有些人也会面对你的问题,并由许多问题引起。

    您可以手动删除第二个背景上的与引导程序的例子,为简短的解决方案。

    更新:

    在亚历山大苏里莫夫的反馈之后,我重新搜索了一遍,发现在Stackoverflow上有一个主题与类似的问题;

    How to hide Bootstrap modal from javascript?

    我用bootstrap代码笔的例子测试它,效果很好

    $("[data-dismiss=modal]").trigger({ type: "click" });
    

    @Alexandr,你能试试下面的代码吗,我理解的就是模仿close with标签;

    $(function(){
       $('#closeWithJS').on('click', function(){
           $("[data-dismiss=modal]").trigger({ type: "click" });
       });
    });
    
    推荐文章