我想創建一個滑塊使用jQuery,但我有困難鏈接我的JavaScript文件到我的HTML。我檢查了語義錯誤,但似乎找不到任何錯誤。有沒有問題的CSS - 只有JavaScript似乎不工作。JavaScript沒有鏈接HTML文件
<!doctype html>
<head>
<title>
content slider
</title>
<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src = "jquery.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body>
<div id="container">
<header>
<h1>JQUERY CONTENT SLIDER</h1>
</header>
<img src = "img/left.png" id="prev" alt="prev" >
<div id="slider">
<div class = "slide" >
<div class = "slide-copy">
<h2>slider 1</h2>
<p background="black">this is slide one</p>
</div>
<img src="img/slider.png">
</div>
<div class="slide " >
<div class= "slide copy">
<h2>slider 2</h2>
<p>this is slide two</p>
</div>
<img src="img/slider1.jpg">
</div>
<div class="slide " >
<div class= "slide copy">
<h2>slider 3</h2>
<p>this is slide three</p>
</div>
<img src="img/slider2.jpg">
</div>
<div class="slide " >
<div class= "slide copy">
<h2>slider 4</h2>
<p background="black">this is slide four</p>
</div>
<img src="img/slider3.jpg">
</div>
<div class="slide" >
<div class= "slide copy">
<h2>slider 5</h2>
<p tex ="black">this is slide five</p>
</div>
<img src="img/2722526.png">
</div>
</div>
<img src = "img/slide-image.png" id="next" alt="next">
</div>
</body>
</head>
</html>
JavaScript文件
$(document).ready(function(){
var speed = 500; //fade spped
var autoswitch = true;//auto slider options
var autoswitch_speed = 4000; //auto slider speed
//add initial active class
$('.slide').first().addclass('active');
//hide all slides
$('.slide').hide();
//shpw first slide
$('active').show();
$('#next').on('click',nextslide);
$('#prev').on('click',prevslide);
//autoslider handler
if(autoswitch == true);{
setinterval(nextslide.autoswitch_speed);
}
// switch to next slide
function nextslide(){
$(active).removeclass('active').addclass('oldactive');
if($('.oldactive').is('last-child')){
$('.slide').first().addclass('active');
}else{
$('.oldactive').next().addclass('active');
}
$('.oldactive').removeclass('oldactive');
$('.slide').fadeout(speed);
$('.active').fadein(speed);
}
});
//
function prevslide(){
$(active).removeclass('active').addclass('oldactive');
if($('.oldactive').is('first-child')){
$('.slide').last().addclass('active');
}else{
$('oldactive').prev().addclass('active');
}
$('.oldactive').removeclass('oldactive');
$('.slide').fadeout(speed);
$('.active').fadein(speed);
}
});
什麼是'$( '激活')顯示() 「應該這樣做?你想選擇「active」類的元素嗎?然後你在選擇器中缺少一個點... – Steve
你也可以使用這個版本不加引號:'$(active)' – Steve
是的,我在第8行做了這個 –