的JavaScript switch語句我想在這裏完成的是,有一個居中的圖像和圖像的下方,在轉盤之外的單獨DIV,顯示報價屬於那個是圖像的旋轉木馬居中。我使用'圓滑'旋轉木馬,旋轉木馬工作正常。 switch語句直接轉到默認情況。改變圖片說明輪盤
JS文件
(function ($) {
'use strict';
$(document).ready(function() {
var $idOne = document.getElementById('1'),
$idTwo = document.getElementById('2'),
$idThree = document.getElementById('3'),
$idFour = document.getElementById('4'),
$idFive = document.getElementById('5'),
$idSix = document.getElementById('6'),
$idSeven = document.getElementById('7'),
$idEight = document.getElementById('8'),
$idNine = document.getElementById('9'),
idArray = [
$idOne, $idTwo, $idThree, $idFour, $idFive, $idSix, $idSeven, $idEight, $idNine
];
switch (idArray) {
case $idOne:
$('#imageCaptions').html("this is image one's caption");
break;
case $idTwo:
$('#imageCaptions').html("this is image two's caption");
break;
case $idThree:
$('#imageCaptions').html("this is image three's caption");
break;
case $idFour:
$('#imageCaptions').html("this is image four's caption");
break;
case $idFive:
$('#imageCaptions').html("this is image five's caption");
break;
case $idSix:
$('#imageCaptions').html("this is image six's caption");
break;
case $idSeven:
$('#imageCaptions').html("this is image seven's caption");
break;
case $idEight:
$('#imageCaptions').html("this is image eight's caption");
break;
case $idNine:
$('#imageCaptions').html("this is image nine's caption");
break;
default:
$('#imageCaptions').html("sorry");
break;
}
});
})(jQuery);
HTML文件
<div id="new">
<div class="center">
<div id="1">
<img src="http://placehold.it/350x300?text=1" class="img-responsive">
</div>
<div id="2">
<img src="http://placehold.it/350x300?text=2" class="img-responsive">
</div>
<div id="3">
<img src="http://placehold.it/350x300?text=3" class="img-responsive">
</div>
<div id="4">
<img src="http://placehold.it/350x300?text=4" class="img-responsive">
</div>
<div id="5">
<img src="http://placehold.it/350x300?text=5" class="img-responsive">
</div>
<div id="6">
<img src="http://placehold.it/350x300?text=6" class="img-responsive">
</div>
<div id="7">
<img src="http://placehold.it/350x300?text=7" class="img-responsive">
</div>
<div id="8">
<img src="http://placehold.it/350x300?text=8" class="img-responsive">
</div>
<div id="9">
<img src="http://placehold.it/350x300?text=9" class="img-responsive">
</div>
</div>
<div id="imageCaptions">
</div>
</div>
'開關(idArray)'是沒有意義的。你有元素,設置他們的標題。 –
我會抓取變量賦值,並嘗試讓你的'case'像這樣:case $('#1'):'另外,什麼是'switch(idArray)'應該做的..? –