Older version conflicting with newer version of jquery

后端 未结 2 615
暗喜
暗喜 2020-12-22 09:14

I am stuck in a major issue with jquery plugins. I have some code written with jquery 1.7.1, now I started using bootstrap and that need 1.9.1 jquery plugin or higher.

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 09:29

    When you load your jQuery.x.x.js, it will overwrite the existing $ and jQuery vars. BUT it keeps a backup copy of them (in _$ and _jQuery). Calling noConflict(true) you restore the situation as it was before your js inclusion!

    noConflict() gives you the running instance (the last loaded), so you can work with you version in this way

    Resuming:

    • original page loads his "jquery.versionX.js"
    • $ and jQuery belong to versionX
    • you call your "jquery.versionY.js"
    • now $ and jQuery belong to versionY, plus _$ and _jQuery that belongs to versionX
    • var my_jQuery = jQuery.noConflict(true);
    • now $ and jQuery belong to versionX, _$ and _jQuery are probably null, and my_jQuery is versionY

    If you want to revert back to a specific version add following JavaScript code in HTML.

    
    

提交回复
热议问题