简体   繁体   中英

can i use any version of jquery using jQuery.noConflict

im using this pluginhttps://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin ,

but my jquery version is 1.4, so i used jQuery.noConflict() because someone said that i can use any version of jquery through this one:

var jq10 = jQuery.noConflict();

but when i try to use the plugin it won't work, it won't have errors too, so i don't know if my code is wrong, or it just doesn't work even with jQuery.noConflict() . Anyone has idea? Here is a sample of what I'm doing, very simple but it doesn't work, or doesn't have any errors to give me a hint

<html>
    <input type="file" name="files[]" id="fileupload" multiple>
</html>

//This is my original version
<script language="javascript" type="text/javascript" src="/scripts/jquery-1.4.2.min.js"></script> 
//This is the minimum version required of the plugin
<script type="text/javascript" src="/scripts/new_jquery/jquery-1.6.4.js"></script>
//These are the requirements for the plugin
<script language="javascript" type="text/javascript" src="/scripts/new_jquery/fileupload/js/vendor/jquery.ui.widget.js"></script>
<script language="javascript" type="text/javascript" src="/scripts/new_jquery/fileupload/js/jquery.iframe-transport.js"></script>
<script language="javascript" type="text/javascript" src="/scripts/new_jquery/fileupload/js/jquery.fileupload.js"></script>

$(document).ready( function() {
    var jq10 = jQuery.noConflict();

    jq10('#fileupload').fileupload({
        dataType: 'json',
        add: function (e, data) {
            console.log(data);
        }
    });
});

You see, i just console logged the data, but it won't return anything with firebug, won't have errors or any to give me a hint of what's going on.

try this:

jQuery.noConflict();
// Do something with jQuery
jQuery( "div p" ).hide();
// Do something with another library's $()
$( "content" ).style.display = "none";

so,

var jq10 = jQuery.noConflict();
jq10(document).ready( function() {

$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        console.log(data);
    }
});
});

Replace everything with this:

<html>
<head>
    <title>Title</title>
</head>
<body>
    <input type="file" name="files[]" id="fileupload" multiple>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="/scripts/new_jquery/fileupload/js/vendor/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="/scripts/new_jquery/fileupload/js/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="/scripts/new_jquery/fileupload/js/jquery.fileupload.js"></script>
    <script>
        $.noConflict();
        jQuery(document).ready(function ($) {
            // Code that uses jQuery's $ can follow here.
            $('#fileupload').fileupload({
                dataType: 'json',
                add: function (e, data) {
                    console.log(data);
                }
            });
        });// Code that uses other library's $ can follow here.
    </script>
</body>
</html>

First of all, someone has told you wrong. You cannot use different versions of jquery, if you use $.noConflict() . ( Ok, you can, but it is not recommended )

But wait !

You shouldn't load two versions of jquery at all. This is just ridiculous if you do that way.

But yes

If you really have to use a plugin that's too old or depends on a older jquery version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM