最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to use $ with externally loaded javascript

programmeradmin0浏览0评论

I'm trying to load an external javascript file that uses jquery but references it with '$'. Through some digging around, I've cobbled together the following:

jQuery(document).ready(function(){
    (function($) {
        $.getScript('.min.js', function() {
            var widget = new TimekitBooking();
            widget.init({
                app_key: 'test_widget_key',
                project_id: '1234'
                // optional configuration here.. (read more under: configuration)
            });
        });
    })( jQuery );       
});

I've then enqueued this script in the footer. However, I keep getting the error 'TypeError: $ is undefined' in line 45 of the loaded script and lines 10 and 15 of this one.

Is this the best method of achieving what I want, and if so, what am I doing wrong?

发布评论

评论列表(0)

  1. 暂无评论