Javascript Src Path

后端 未结 8 1250
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 04:46

Hello I\'m having some trouble with the following code within my Index.html file:




        
相关标签:
8条回答
  • 2020-12-15 05:11
    src="/clock.js"
    

    be careful it's root of the domain.

    P.S. and please use lowercase for attribute names.

    0 讨论(0)
  • 2020-12-15 05:17

    Try:

    <script src="/clock.js"></script>
    

    Note the forward slash.

    0 讨论(0)
  • 2020-12-15 05:18

    The common practice is to put scripts in a discrete folder, typically at the root of the site. So, if clock.js lived here:

    /js/clock.js
    

    then you could add this code to the top of any page in your site and it would just work:

    <script src="/js/clock.js" type="text/javascript"></script>
    
    0 讨论(0)
  • 2020-12-15 05:26

    Piece of cake!

    <SCRIPT LANGUAGE="JavaScript" SRC="/clock.js"></SCRIPT>
    
    0 讨论(0)
  • 2020-12-15 05:27

    If you have

    <base href="/" />
    

    It's will not load file right. Just delete it.

    0 讨论(0)
  • 2020-12-15 05:29

    This works:

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

    The leading slash means the root directory of your site. Strictly speaking, language="Javascript" has been deprecated by type="text/javascript".

    Capitalization of tags and attributes is also widely discouraged.

    0 讨论(0)
提交回复
热议问题