gpt4 book ai didi

php - 我有 2 个 JS 文件。如何让第二个 JS 文件仅在*第一个 JS 文件加载完成后运行?

转载 作者:行者123 更新时间:2023-11-28 05:25:59 25 4
gpt4 key购买 nike

我有 2 个 JS 文件。如何让第二个 JS 文件仅在 第一个 JS 文件加载完成后运行?有没有办法明确设置它?

最佳答案

基于这个答案How do I load a javascript file dynamically?

您可以从第一个文件动态加载第二个文件。这样您就可以确定第一个已完全加载。

  // DOM: Create the script element
var jsElm = document.createElement("script");
// set the type attribute
jsElm.type = "application/javascript";
// make the script element load file
jsElm.src = file;
// finally insert the element to the body element in order to load the script
document.body.appendChild(jsElm);

关于php - 我有 2 个 JS 文件。如何让第二个 JS 文件仅在*第一个 JS 文件加载完成后运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32370240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com