var ele = document.createElement("script");
var scriptPath = "http://localhost:8080/{scriptfilename}.js" //verify the script path
ele.setAttribute("src",scriptPath);
document.head.appendChild(ele)
Look at where your html file is, the path you provided is relative not absolute. Are you sure it's placed correctly. According to the path you gave in the example above: "src="../js/moment.js" " the JS file is one level higher in hierarchy.
因此,它应该放置如下:
使用 Chrome 浏览器和 Web Server for Chrome 扩展,设置一个默认文件夹并将链接的 html/js 文件放入其中,浏览到 Chrome 中的127.0.0.1:8887(0r 不管端口设置在哪里)并打开开发者面板和控制台。然后您可以在控制台中与您的 html/js 脚本交互。
# 1. Install Python 3 & use:
python3 -m http.server
# On windows, instead of "python3" try "python" or "py -3"
# If you installed python version 2 then use:
python -m SimpleHTTPServer
# 2. To serve a specific folder use the --directory flag:
python3 -m http.server --directory /Users/junaid/WebstormProjects
# Note: I use MacOs & I have given the absolute path to my projects folder & I was able to serve my desired folder.