Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
location.href = '/';
适用于在线网站,但在本地硬盘驱动器上测试源时失败(根目录是 C:// 或 file:// 或类似的)
您如何在线和本地磁盘上访问您的网站根索引页面?
你不这样做是因为文件 url 没有单一的“基础”,所以你尝试的首先没有任何意义。
如果你想正确地测试你的代码,你应该安装一个网络服务器——否则环境会非常不同,因此无论如何都不适合测试。