开发者

jQuery: running 2 different jQuery versions on the same website?

开发者 https://www.devze.com 2023-01-04 20:05 出处:网络
can I run 2 different jQuery versions on the same website and avoid confl开发者_开发技巧icts ?

can I run 2 different jQuery versions on the same website and avoid confl开发者_开发技巧icts ?

please don't ask me why.. it is a long story.

Thanks!


Your html knows only know what you tell it, so if you have something like this in your HEAD section

<script src="<%= Url.Content("~/Scripts/jquery-1.4.2.min.js")%>" type="text/javascript"></script>

instead of the below on a given page in your website there shouldn't be a problem.

<script src="<%= Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" type="text/javascript"></script>

However, I would not try to reference both versions from any given page as I would expect that to invite method name collisions...


well it should be possible, you will have to update your scripts though.

The idea is not all that difficult: include the least often used version first

then add this script

<script type="text/javascript">
   window.jQueryOld = jQuery;
</script>

then add the more often used version.

now you only have to update your scripts that use the old (or new version withchever it is) to use not the $ or jQuery variable, but the jQueryOld variable


Different versions you would get problems. define the includes in the head. You can use obviously different plugins/addons.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号