简体   繁体   中英

Cannot add js file using script tag

This seems like a rather dumb question to ask but I would like to resolve this quickly and start working.I have a folder in which my html resides and I have the javascript files in a seperate folder called js .I have tried to add the script like this:

<script type="text/javascript" src="js/gmaps.js">

and I have also tried like this:

<script type="text/javascript" src="./js/gmaps.js"> 

I have even tried like this:

<script type="text/javascript" src="/js/gmaps.js">

As far as I understand either of the first two should work:

 / root folder
./ current folder
../one folder up

The paths of the files are

 /home/anr/Desktop/maps/server/client/js/gmaps.js
 /home/anr/Desktop/maps/server/client/google_maps.html

UPDATE:

The js file has window.onload and it also creates another script tag programmatically and adds it to the dom,after moving to the external script file I find that the map does not load

看起来您只需要在第一个示例上使用来关闭脚本标签即可,这应该可以工作。

Be sure that you are closing your tag as well. Once you have the correct relative path, your syntax should be:

<script type="text/javascript" src="relative_path_here"></script>

The following link could be helpful for setting the relative path in HTML: Basic HTML - how to set relative path to current folder?

Try this,

<script type="text/javascript" src="js/gmaps.js"></script>

The script tag should be closed

<script type="text/javascript" src="js/gmaps.js"></script> 标签应关闭

I also had a similar problem but not with the path. My problem is the encoding of the html file in my demo, change encoding to ASNI to fix problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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