admin管理员组

文章数量:1387381

I'm new with javascript, so i'm trying to use two jQuery plugins, together they don't work properly. Just if i remove one of two.

How can i resolve this problem ? I could paste both .js files, but that is 2k lines of code, I don't want bother you with so many lines of code.

  • jQuery.autoplete.js

  • Greybox plugin AJS.js

Or if you know some plugin that do some functionality, will help too =)

-- UPDATE:

Thank you guys, (i'm not able to add ment in your answers (i really don't know why), some problem with the site.) @Mörre i noted when i remove this line in AJS.js it works (part of it) :

AJS.exportToGlobalScope();

But after that I don't know what to do, sorry guys, I'm new in javascript so many things that you said I don't understand.

@Jim, i don't find any:

$(document).ready(function() { });

the replace by jQuery as you said.

I try to replace all '$' by 'jQuery', and still doesn't work.

I'm new with javascript, so i'm trying to use two jQuery plugins, together they don't work properly. Just if i remove one of two.

How can i resolve this problem ? I could paste both .js files, but that is 2k lines of code, I don't want bother you with so many lines of code.

  • jQuery.autoplete.js

  • Greybox plugin AJS.js

Or if you know some plugin that do some functionality, will help too =)

-- UPDATE:

Thank you guys, (i'm not able to add ment in your answers (i really don't know why), some problem with the site.) @Mörre i noted when i remove this line in AJS.js it works (part of it) :

AJS.exportToGlobalScope();

But after that I don't know what to do, sorry guys, I'm new in javascript so many things that you said I don't understand.

@Jim, i don't find any:

$(document).ready(function() { });

the replace by jQuery as you said.

I try to replace all '$' by 'jQuery', and still doesn't work.

Share Improve this question edited Nov 4, 2014 at 7:25 Chris Martin 30.8k12 gold badges80 silver badges140 bronze badges asked Mar 5, 2011 at 13:00 Valter SilvaValter Silva 16.7k53 gold badges141 silver badges221 bronze badges 1
  • "They don't work properly" does not adequately describe what is going wrong for you. Are there JavaScript errors in the console when you load the page? Do aspects of the plugins not work? Are there page layout issues? There are many possibilities but you've told us nothing. – Pointy Commented Mar 5, 2011 at 13:06
Add a ment  | 

2 Answers 2

Reset to default 3

Valter,

you may find that there's a collision on the $ alias going on. you'll possibly get it to work if you explicity reference jquery object using the full jquery alias i.e rather than:

<script type="text/javascript">
    $(document).ready(function() {

    });
</script>

try:

<script type="text/javascript">
    jQuery(document).ready(function() {

    });
</script>

change any $ references to jQuery in the client code when using the autoplete lib.

just a thought if it's in relation to this'area'

Without checking any further after looking at the code briefly, the AJS code puts everything in a global object AJS at first - but then exports every single property of that object into the global namespace. Bad behavior. The first one is a regular jQuery plugin. Remendation: Don't use AJS, or remove the export to global space (you then just call AJS methods by prefixing them with "AJS.").

本文标签: jqueryConflict with 2 javascript filesStack Overflow