Jquery with bootstrap 4



当我在使用引导程序时运行这些代码时出现以下错误

练习.js:11 未捕获的类型错误: $(...(。淡出不是函数

我的代码:-

.HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed&display=swap" rel="stylesheet">
<link rel="stylesheet" href="practice.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.js"></script>
<title></title>
</head>
<body>

<div id="effect" class="row my-5">
<div class="col-3"></div>
<div class="col-6">
<img class="img-fluid" src="https://scontent.fjrs1-1.fna.fbcdn.net/v/t1.15752-9/107376723_279529570050364_381202387595922170_n.jpg?_nc_cat=100&_nc_sid=b96e70&_nc_ohc=zXTVBn-CzdsAX_OnKdo&_nc_ht=scontent.fjrs1-1.fna&oh=68eafa443772a6c0d0e773c1d6f794c4&oe=5F2853BC"
alt="">
</div>
<div class="col-3"></div>
</div>

<script src="practice.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

JavaScript :

$("#effect").on("click", function() {
$(this).fadeOut();
});

你正在加载jQuery两次。

首先,加载jquery-2.1.4.js(已过时,存在已知的安全问题,不应使用(。

然后你加载jquery-3.2.1.slim.min.js(这是过时的,等等,不包括你尝试使用的效果模块!


加载 jQuery一次,使其成为当前版本 (3.5.1(,如果您需要不包含的功能,请不要使用精简版本。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed&display=swap" rel="stylesheet">
<link rel="stylesheet" href="practice.css">
<title></title>
</head>
<body>

<div id="effect" class="row my-5">
<div class="col-3"></div>
<div class="col-6">
<img class="img-fluid" src="https://scontent.fjrs1-1.fna.fbcdn.net/v/t1.15752-9/107376723_279529570050364_381202387595922170_n.jpg?_nc_cat=100&_nc_sid=b96e70&_nc_ohc=zXTVBn-CzdsAX_OnKdo&_nc_ht=scontent.fjrs1-1.fna&oh=68eafa443772a6c0d0e773c1d6f794c4&oe=5F2853BC"
alt="">
</div>
<div class="col-3"></div>
</div>

<button class="btn1">Fade out</button>
<button class="btn2">Fade in</button>

<script src="practice.js"></script>

<script>
$(".btn1").click(function(){
$("img").fadeOut();
});
$(".btn2").click(function(){
$("img").fadeIn();
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
你可以做这样的事情.jQuery在你的代码中没有正确定义,因为错误

最新更新