[英]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.