![](/img/trans.png)
[英]How do I add next and previous buttons to my slideshow with jQuery?
[英]my if condition wont hide accordingly my next and previous buttons
我需要一個隱藏第一頁= 1上一個按鈕的if條件,並且在第8頁上它隱藏了下一個按鈕我確實使用了下面的代碼並嘗試但它沒有相應地隱藏:
var page = 8; if(page == 0){ $("#prev-button").hide(); $("#next-button").show(); }else if (page == 8) { $("#prev-button").show(); $("#next-button").hide(); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="load-more" id="next-button"> <a href="${nextUrl}" class="btn-on-white white">Next</a> </div> <div class="previous" id="prev-button"> <a href="${prevUrl}" class="btn-on-white-test white">Prev</a> </div>
也許這會幫助您實現目標:
var page = 0;
$("#prev-button").hide();
$("#next-button").show();
function showBoth() {
if (page < 8 && page > 0) {
$("#prev-button").show();
$("#next-button").show();
}
}
$("#prev-button").on("click", function () {
page--;
showBoth();
if (page == 0) $(this).hide();
});
$("#next-button").on("click", function () {
page++;
showBoth();
if (page == 8) $(this).hide();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.