简体   繁体   English

外部Js文件未加载

[英]External Js file not loading

Is there a reason this doesnt work? 这有什么原因吗?

<!DOCTYPE html>
 <html>
   <head>
     <script 

     <script
      src="C:/Users/juniper/Documents/practiceCode/public/server/screen.js">
     </script>
     </head> 
    <body>
     <img src="blue.png" usemap="#map">
    <map name="map">
    <area shape="rect" coords="0,0,400,160" onclick="hideScreen()">
   </map>
   <style>
    img {
    height: 100%;
    width: 100%;
    }
     map {
   position: absolute;
   }
  </style>

This is the screen.js 这是screen.js

  function hideScreen() {
    alert("hitBackButton");
  }

the point is it sends out an alert when I press that section of the hotmap, However I think it doesn't work because the screen.js file is used after this file. 关键是当我按下热图的那一部分时它会发出警报,但我认为它不起作用,因为在此文件之后使用了screen.js文件。 So it doesnt load in time. 所以它没有及时加载。 what could be the issue with the external js file? 什么可能是外部js文件的问题?

<script src="C:/Users/O77616/Documents/practiceCode/public/server/screen.js">         </script>
        ^ not <src

update 更新

if you're running a server you can use path 如果您正在运行服务器,则可以使用路径

<script src="http://SERVER/public/server/screen.js"></script>

or if not then use a relative path from the folder the html file is running 或者如果没有,则使用html文件正在运行的文件夹中的相对路径

<script src="/public/server/screen.js"></script>

Change: 更改:

 <script 
  <src="C:/Users/O77616/Documents/practiceCode/public/server/screen.js">
 </script>

To: 至:

 <script src="relativePathToFolder/screen.js"></script>

And, don't use absolute file system paths. 并且,不要使用绝对文件系统路径。 Use a relative path. 使用相对路径。

非常确定你的页面不知道c:驱动器位置,如果你想提供一个本地使用的file://c:/...只有它的file://c:/...否则你必须放在像apache,nginx这样的web服务器上,如果你想要一个简单的Web服务器,你可以从命令行启动并指向一个目录,你可以尝试devd.io。

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

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