当在JavaScript中调用函数时,循环不会完成执行

时间:2017-07-25 16:33:03

标签: javascript css function for-loop

我正在使用以下函数创建并链接到<head>标记中的样式表,具体取决于传递的URL。

function create(file) {
    var link = document.createElement("link");
    link.href = "https://example.com/" + file;
    link.rel = "stylesheet";
    document.head.appendChild(link);
}    

我有一个for循环,无论何时调用该函数都不会停止运行。

    for(i=0; i<array.length; i++){
          theFile = array[i];
          create(theFile);
    }

array内只是一个CSS文件列表 - "bootstrap.min.css", "font-awesome.min.css"

我已经测试了它自己的功能,它似乎工作正常:

create("style.css");  
create("style.css");

上面的代码设法在<head>标记中创建两个样式表。

0 个答案:

没有答案
相关问题