简体   繁体   English

我可以使用 jQuery.noConflict 使用任何版本的 jquery

[英]can i use any version of jquery using jQuery.noConflict

im using this pluginhttps://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin ,我正在使用这个插件https://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:但是我的 jquery 版本是 1.4,所以我使用了jQuery.noConflict()因为有人说我可以通过这个使用任何版本的 jquery:

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() .但是当我尝试使用该插件时它不起作用,它也不会出现错误,所以我不知道我的代码是否错误,或者即使使用jQuery.noConflict()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() .如果使用$.noConflict() ,则不能使用不同版本的 jquery。 ( Ok, you can, but it is not recommended ) 好吧,你可以,但不推荐

But wait !可是等等 !

You shouldn't load two versions of jquery at all.您根本不应该加载两个版本的 jquery。 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.如果您真的必须使用太旧的插件或依赖于较旧的 jquery 版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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