How to include an external plugin inside of another jQuery plugin being authored

前端 未结 2 1757
礼貌的吻别
礼貌的吻别 2021-01-12 20:47

I am building a custom jQuery plugin for a project I am working on. I want to return an object that is custom to another jQuery plugin...rather than having to make sure that

相关标签:
2条回答
  • 2021-01-12 20:56

    You can also use getScript function from jQuery.

    It could be used with callbacks for success and/or failure like:

    $.getScript("somejs.js", function(data, textStatus, jqxhr) {
        console.log("callback");    
    }
    
    $.getScript("somejs.js")
    .done(function(script, textStatus) {
        console.log("done callback");
    })
    .fail(function(jqxhr, settings, exception) {
        console.log("fail callback");
    });      
    

    Or without assigning a callback like:

    $.getScript("somejs.js");            
    
    0 讨论(0)
  • 2021-01-12 21:05

    Sure - you can create a new script element and append it to the head.

    var script = document.createElement('script');
    script.src = 'url-to-plugin';
    script.type = 'text/javascript';
    document.getElementsByTagName('head')[0].appendChild(script);
    

    If this doesn't work, maybe try the method on this page, it's a slightly different approach using setAttribute.

    0 讨论(0)
提交回复
热议问题