jQuery多個版本或和其他js庫沖突主要是常用的$符號的問題,這個問題 jquery早早就有給我們預(yù)留處理方法了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多個jquery版本沖突解決方案</title>
<script src="jquery.js"></script>
<script>
var j14 = jQuery.noConflict(true);
</script>
<script src="jquery-1.8.3.min.js"></script>
<script >
var j18 = jQuery.noConflict(true);
</script>
<script src="jquery-3.3.1.min.js"></script>
<script >
var j33 = jQuery.noConflict(true);
</script>
</head>
<body>
<input type="button" id="t1" value="測試1">
<input type="button" id="t2" value="測試2">
<input type="button" id="t3" value="測試2">
<script>
j14(document).ready(function($){
//繼續(xù)使用 jquery1.4 的 $
$("#t1").click(function(){
$(this).val("j14測試");
})
})
j18(document).ready(function($){
//繼續(xù)使用 jquery1.8 的 $
$("#t2").click(function(){
$(this).val("j18測試");
})
})
j33(document).ready(function($){
//繼續(xù)使用 jquery33 的 $
$("#t3").click(function(){
$(this).val("j33測試");
})
})
</script>
</body>
</html>
