代码之家  ›  专栏  ›  技术社区  ›  Phillip Senn mpgn

包含一个JavaScript文件[副本]

  •  12
  • Phillip Senn mpgn  · 技术社区  · 14 年前

    可能的重复:
    Include javascript file inside javascript file?
    How do you dynamically load a javascript file? (Think C's #include)

    你知道的:就像我在.css文件的顶部链接.css文件一样。

    Some sort of @import yyy.js
    followed by other js commands.
    
    4 回复  |  直到 8 年前
        1
  •  6
  •   John Boker    14 年前

    这是我的解决方法:

    if (typeof (jQuery) == "undefined") 
        document.write(unescape("%3Cscript src='" + server_url + "/js/jquery-1.4.2.min.js' type='text/javascript'%3E%3C/script%3E"));
    

    当然,对于jquery以外的任何东西,您都必须弄清楚是否需要它,然后对该文件执行相同的操作。

    还需要设置服务器url。

    http://my.digitalscout.com/Widgets/schedule.html

        2
  •  7
  •   casablanca    14 年前

    不,没有。您要么将其包含在HTML中,要么使用JavaScript创建 <script> 标记并附加到文档上。

        3
  •  2
  •   Chase Florell    14 年前

    /// <reference path="yyy.js" />
    

    引用只是添加了智能感知支持。

        4
  •  1
  •   Matthew Vines    14 年前

    如果您在服务器端环境中,则可以执行此操作。例如,在php中,您可以使用include语句,但您必须标记文件“.php”而不是“.js”,这样预处理器将在其上运行。