1
我想用一個腳本來製作一個簡單的滑塊。在jsfiddle上完美工作,但不是當我複製/粘貼網上的每一個parte時,我正在做...有什麼問題? 我將不勝感激任何幫助。簡單的jQuery滑塊
感謝
var $first = $('li:first', 'ul'),
$last = $('li:last', 'ul');
$("#next").click(function() {
var $next, $selected = $(".selected");
$next = $selected.next('li').length ? $selected.next('li') : $first;
$selected.removeClass("selected");
$next.addClass('selected');
});
$("#prev").click(function() {
var $prev, $selected = $(".selected");
$prev = $selected.prev('li').length ? $selected.prev('li') : $last;
$selected.removeClass("selected");
$prev.addClass('selected');
});
li {display:none}
.selected {display:block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="prev">Previous</button>
<button id="next">Next</button>
<div>
<ul id="">
<li id="pic1"><img src="http://www.cooksmarts.com/wp-content/uploads/2015/09/Pantry-Essentials-Lemons-400x250.jpg" alt="pic1"></li>
<li id="pic2"><img src="https://tendertummys.com/wp-content/uploads/tomatoes-2.jpg" alt="pic2"></li>
<li id="pic3"><img src="http://med.news.am/static/news/b/2014/08/3031.jpg" alt="pic3"></li>
</ul>
</div>
建立的解決方案:在腳本中缺少$(function()。 – Danielillo