如何使用Jquery导入Canvas.js?

时间:2017-12-28 06:26:42

标签: jquery html canvas

如何使用Jquery导入Canvas.js?

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script src="https://canvasjs.com/assets/script/jquery.canvasjs.min.js"></script>

是否有任何Jquery代码替换上面的html代码?

1 个答案:

答案 0 :(得分:1)

试试这段代码,

appendScriptToDocument("https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js", "jquery-3.2.1.min.js");
appendScriptToDocument("https://canvasjs.com/assets/script/jquery.canvasjs.min.js", "jquery.canvasjs.min.js");

function appendScriptToDocument(url, name){
    var scriptLoader = document.createElement('script');
    scriptLoader.src = url;
    scriptLoader.scriptname = name;
    scriptLoader.async = false;
    //scriptLoader.addEventListener("load", scriptFileLoadSuccessCallback, false);// If you want to run any function after load success.
    document.head.insertBefore(scriptLoader, document.head.firstChild);
}

这里我在javascript的帮助下为文档添加了一个脚本元素。