微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 使用requireJS的Tooltip系绳

Bootstrap的最新测试版(v4)使用Tether js来定位元素,我无法让它在我的Requirejs应用程序中工作.

在我的requirejs配置我有以下垫片的

paths: {
    jquery: '/path/to/jquery',tether: '/path/to/tether'
},shim: { 
     'bootstrap': ['tether','jquery']       
}

当我想在我的应用程序中激活工具提示时,我使用以下代码,我认为是正确的

function page_events() {
    requirejs(['bootstrap'],function(bootstrap) {
        $('[data-toggle="tooltip"]').tooltip(); 
    }); 
}

这应该首先加载引导依赖关系,然后执行代码.所以在这代码之前应该包括系带.

但控制台的结果是

Uncaught ReferenceError: Tether is not defined

有人有同样的问题吗?

解决方法

创建一个这样的脚本:
define(['lib/tether.min'],function(tether) {
    window.Tether = tether;
    return tether;
});

然后改变这个:

paths: {
    jquery: '/path/to/jquery',// tether: '/path/to/tether'
    tether: '/path/to/your-own-tether'
},'jquery']       
}

为什么?因为浏览器需要这样:

window.Tether = tether; // May be both requirejs and tether didn't do this

原文地址:https://www.jb51.cc/js/152186.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐