How Can I remove Conflict in my Jquery?

后端 未结 1 1888
我在风中等你
我在风中等你 2021-01-16 03:26

I am new to JQuery And I have used 2 jQueries in my page.

For first JQuery my script is like this:



        
相关标签:
1条回答
  • 2021-01-16 04:05

    It is your 2nd jQuery script you should be performing $.noConflict() on.

    If you do;

    <script src="http://code.jquery.com/jquery-1.7.js"></script>
    <script>
        var jq = $.noConflict();
        jq(function() {
             jq( "#my_tabs" ).tabs({
             event: "click" //click
             });            
        });
    </script>
    <script src="http://code.jquery.com/jquery-1.4.js"></script>
    

    Both jQuery and $ will point to jQuery 1.4, and nothing will refer to jQuery 1.7. Incidentally, if you were to run $.noConflict again after loading jQuery 1.4, jQuery would reference 1.4, but $ would be undefined.

    However, if you do:

    <script src="http://code.jquery.com/jquery-1.7.js"></script>
    <script src="http://code.jquery.com/jquery-1.4.js"></script>
    <script>
        var jq = $.noConflict();
        jq(function() {
             jq( "#my_tabs" ).tabs({
             event: "click" //click
             });            
        });
    </script>
    

    The $ will refer to jQuery 1.7, but the jQuery will point to jQuery 1.4 (as will your jq variable).

    You may want to look at the $.noConflict(true); which releases both the jQuery and $ variables; so you can do something like this;

    <script src="http://code.jquery.com/jquery-1.7.js"></script>
    <script src="http://code.jquery.com/jquery-1.4.js"></script>
    <script>
        var jq = $.noConflict(true);
        jq(function() {
             jq( "#my_tabs" ).tabs({
             event: "click" //click
             });            
        });
    </script>
    

    Then both the $ and jQuery will point to jQuery 1.7, and only your jq variable will point to jQuery 1.4

    0 讨论(0)
提交回复
热议问题