picking jQuery 1.9 or 2.0 using JavaScript and Require.JS

后端 未结 2 978
陌清茗
陌清茗 2021-02-01 10:19

jQuery 2.0 is increasingly mature: http://blog.jquery.com/2013/03/01/jquery-2-0-beta-2-released/

jQuery 2.0 breaks compatibility with older browsers, so one must know wh

2条回答
  •  难免孤独
    2021-02-01 10:24

    Adaptation of niaccurshi's answer to AMD spec.

    // Do this before your first use of jQuery.
    
    var pathToJQuery
    if('querySelector' in document
        && 'localStorage' in window
        && 'addEventListener' in window) {
        pathToJQuery = '//cdn/jQuery2.0'
    } else {
        pathToJQuery = '//cdn/jQuery1.9'
    }
    
    require.configure({'paths':{
        'jquery': pathToJQuery
    }})
    
    require(['jquery'], function($){ /* you get the one you need here */ })
    

提交回复
热议问题