t4st
V2EX  ›  问与答

如何在js文件中引入jQuery?

  •  
  •   t4st · Mar 16, 2013 · 7197 views
    This topic created in 4834 days ago, the information mentioned may be changed or developed.
    求助,如果用document.createElement的方法加载的话,会有' $ is not defined '错误发生。
    6 replies    1970-01-01 08:00:00 +08:00
    airyland
        1
    airyland  
       Mar 16, 2013
    AMD/CMD 规范
    t4st
        2
    t4st  
    OP
       Mar 16, 2013
    @airyland google了一下,还是不明白,前端新手一枚,可以说的细一点么?
    franky_xhl
        3
    franky_xhl  
       Mar 16, 2013 via iPad
    t4st
        4
    t4st  
    OP
       Mar 16, 2013
    不使用其他框架可以实现么?
    Betty
        5
    Betty  
       Mar 16, 2013
    如何在动态添加script标签时确保执行顺序
    http://www.cnblogs.com/sanshi/archive/2011/02/28/1967367.html
    chrisyipw
        6
    chrisyipw  
       Mar 16, 2013
    你需要保证 $ 调用前,动态插入的 <script> 已经下载好,这种问题最常见于利用改 mime 类型或 async 等异步下载执行的情况。
    最简单的是在 onload 里才执行 jQuery 有关的代码:

    document.createElement('script').onload = function(){ if (window.$){ /* do sth. */ } }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2659 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    ♥ Do have faith in what you're doing.