开发者

If I include Prototype and jQuery, why does inline jQuery conflict (over use of $) but not included jQuery files?

开发者 https://www.devze.com 2023-02-04 04:48 出处:网络
If Prototype is included in the page already, I have to do this: jQuery(document).ready(function() { for inline jQuery scripts instead of this:

If Prototype is included in the page already, I have to do this:

jQuery(document).ready(function() 
{

for inline jQuery scripts instead of this:

$(document).ready(function() 
{

But if I have an included jQuery file on th开发者_如何学运维e same page that uses $, that does not seem to conflict, e.g.:

<script type='text/javascript' src='/js/included.js'></script>

In other words, I don't have to edit included.js and change all of the $ to jQuery.

Why the distinction: included files versus inline scripts?


included may be playing safe and deliberately shadowing $

(function($) {
  // included.js code here
})(jQuery);
0

精彩评论

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