t4st
V2EX  ›  问与答

如何在js文件中引入jQuery?

  •  
  •   t4st · Mar 16, 2013 · 7508 views
    This topic created in 4995 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
    airyland
    Mar 16, 2013
    1
    AMD/CMD 规范
    t4st
    t4st
    OP
    Mar 16, 2013
    2
    @airyland google了一下,还是不明白,前端新手一枚,可以说的细一点么?
    franky_xhl
    franky_xhl
    Mar 16, 2013 via iPad
    3
    t4st
    t4st
    OP
    Mar 16, 2013
    4
    不使用其他框架可以实现么?
    Betty
    Betty
    Mar 16, 2013
    5
    如何在动态添加script标签时确保执行顺序
    http://www.cnblogs.com/sanshi/archive/2011/02/28/1967367.html
    chrisyipw
    chrisyipw
    Mar 16, 2013
    6
    你需要保证 $ 调用前,动态插入的 <script> 已经下载好,这种问题最常见于利用改 mime 类型或 async 等异步下载执行的情况。
    最简单的是在 onload 里才执行 jQuery 有关的代码:

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