繁体   English   中英

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

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

我正在使用这个插件https://github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin

但是我的 jquery 版本是 1.4,所以我使用了jQuery.noConflict()因为有人说我可以通过这个使用任何版本的 jquery:

var jq10 = jQuery.noConflict();

但是当我尝试使用该插件时它不起作用,它也不会出现错误,所以我不知道我的代码是否错误,或者即使使用jQuery.noConflict()jQuery.noConflict() 有人有想法吗? 这是我正在做的一个示例,非常简单但它不起作用,或者没有任何错误给我提示

<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);
        }
    });
});

你看,我只是控制台记录了数据,但它不会用萤火虫返回任何东西,不会有错误或任何提示我正在发生的事情。

尝试这个:

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

所以,

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

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

用这个替换所有内容:

<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>

首先,有人告诉你错了。 如果使用$.noConflict() ,则不能使用不同版本的 jquery。 好吧,你可以,但不推荐

可是等等 !

您根本不应该加载两个版本的 jquery。 如果你这样做,这太荒谬了。

但是,是的

如果您真的必须使用太旧的插件或依赖于较旧的 jquery 版本。

暂无
暂无

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

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