[英]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.