简体   繁体   English

为什么我的插入脚本标签不可见?

[英]Why Aren't My Inserted Script Tags Visible?

I'm loading a block of script tags with a for loop from a js file. 我正在从js文件中加载一个带for循环的脚本标签块。 That works as functions are called, but I don't understand why the script tags are not on the document in source view. 这在调用函数时起作用,但是我不明白为什么脚本标记不在源视图中的文档上。

For example: 例如:

for (var str in library) {
    document.write("<script src='" + "scriptsfolder/" + "" + library[str] + "'></script>");
}

Where are those scripts written to? 这些脚本写在哪里? And why does this work? 为何这样做呢?

The for loop is called after js file is loaded. 加载js文件后,将调用for循环。

Most browsers, when using "View Source", make a new request to the server to fetch the HTML for the page, and do not execute JavaScript. 大多数浏览器在使用“查看源代码”时会向服务器发出请求,以获取页面的HTML,并且不执行JavaScript。 Use the browser's debugger/inspector (eg right click -> "Inspect Element" in Chrome) and you will see your new script tags. 使用浏览器的调试器/检查器(例如,在Chrome中右键单击->“检查元素”),您将看到新的脚本标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM