[英]How to add prev/next button within looping?
我在下面的彈出窗口中找到了此JavaScript代碼。 它工作正常。 但是我需要繼續加載彈出窗口而不退出(以圓圈為單位)。 因此,如何為按鈕添加循環。
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if (pNode.prev(".modalDialog")) {
var id = pNode.prev(".modalDialog").attr("id");
window.location.href = "#" + id;
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if (pNode.next(".modalDialog")) {
var id = pNode.next(".modalDialog").attr("id");
window.location.href = "#" + id;
}
});
});
可以做到這一點:
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog"),
id = pNode.prev(".modalDialog").attr("id") ||
$('.modalDialog').last().attr("id");;
window.location.href = "#" + id;
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog"),
id = pNode.next(".modalDialog").attr("id") ||
$('.modalDialog').first().attr("id");
window.location.href = "#" + id;
});
});
小提琴 。 如果沒有,則先執行。 如果沒有上一個,則需要倒數第二個。
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.prev(".modalDialog")){
var id = pNode.prev(".modalDialog").attr("id");
if (id != undefined)
window.location.href = "#" + id;
else {
var id = $(".modalDialog").last().attr("id");
window.location.href = "#" + id;
}
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.next(".modalDialog")){
var id = pNode.next(".modalDialog").attr("id");
if (id != undefined)
window.location.href = "#" + id;
else {
var id = $(".modalDialog").first().attr("id");
window.location.href = "#" + id;
}
}
});
});
$(document).ready(function() {
$(".getAssignment2").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.prev(".modalDialog").length > 0){
if(pNode.prev(".modalDialog")){
var id = pNode.prev(".modalDialog").attr("id");
window.location.href = "#" + id;
}
}else{
if(pNode.prev(".modalDialog")){
var id = $(".modalDialog:nth-last-of-type(1)").attr("id");
window.location.href = "#" + id;
}
}
});
$(".getAssignment").click(function() {
var pNode = $(this).closest(".modalDialog");
if(pNode.next(".modalDialog").length > 0){
if(pNode.next(".modalDialog")){
var id = pNode.next(".modalDialog").attr("id");
window.location.href = "#" + id;
}
}else{
if(pNode.next(".modalDialog")){
var id = $(".modalDialog:nth-of-type(1)").attr("id");
window.location.href = "#" + id;
}
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.