javascript - 引导模式中下一个按钮的 if 语句
问题描述
我遇到了一个快速的问题,我不知道在我的页面中为 if 给出什么条件,这样可以确保在单击下一步时模态内容从最后一个到最后一个。
$("#next-btn").on("click", function() {
if (currentMarineKnotIndex - 1 == 0) {
currentMarineKnotIndex = receivedArray.length - 1;
} else {
currentMarineKnotIndex++;
}
$("#marine-knot-div").html(receivedArray[currentMarineKnotIndex].nameLV + "<br>" + receivedArray[currentMarineKnotIndex].descriptionLV);
$("#modal-header-div").css("background", "url('../Images/uploads/" + receivedArray[currentMarineKnotIndex].Image + "')");
});
$("#prev-btn").on("click", function() {
if (currentMarineKnotIndex + 1 == 0) {
currentMarineKnotIndex = receivedArray.length - 1;
} else {
currentMarineKnotIndex--;
}
$("#marine-knot-div").html(receivedArray[currentMarineKnotIndex].nameLV + "<br>" + receivedArray[currentMarineKnotIndex].descriptionLV);
$("#modal-header-div").css("background", "url('../Images/uploads/" + receivedArray[currentMarineKnotIndex].Image + "')");
});
我使它适用于上一个按钮,但我不知道下一步该做什么。
解决方案
你只需要改变条件..
$("#next-btn").on("click", function() {
if(currentMarineKnotIndex-1 == receivedArray.length){
currentMarineKnotIndex = receivedArray.length -1;
}
else{
currentMarineKnotIndex++;
}
$("#marine-knot-div").html(receivedArray[currentMarineKnotIndex].nameLV+"<br>"+receivedArray[currentMarineKnotIndex].descriptionLV);
$("#modal-header-div").css("background", "url('../Images/uploads/"+receivedArray[currentMarineKnotIndex].Image+"')");
});
$("#prev-btn").on("click", function() {
if(currentMarineKnotIndex+1 == 0){
currentMarineKnotIndex = receivedArray.length - 1;
}else{
currentMarineKnotIndex--;
}
$("#marine-knot-div").html(receivedArray[currentMarineKnotIndex].nameLV+"<br>"+receivedArray[currentMarineKnotIndex].descriptionLV);
$("#modal-header-div").css("background", "url('../Images/uploads/"+receivedArray[currentMarineKnotIndex].Image+"')");
推荐阅读
- node.js - 网页呈现,但第一次使服务器崩溃,然后呈现而不会使服务器随后崩溃
- java - Junit Mokito 总是返回空值
- ios - 从其他 iOS 应用打开 iOS 应用时获取应用引荐来源网址
- php - 运行 php artisan cache:clear Declaration of Symfony\Component\Translation\TranslatorInterface::setLocale($locale) 后出现错误
- modelica - Dymola中使用牛顿迭代法的详细过程
- angular - 使用 PWA 版本的 Angular App 时出现 404
- outlook - 使用 Outlook Web 加载项记录传入和传出电子邮件
- javascript - 无法在 typescript 中配置 Apolloserver 的数据源
- macos - 需要帮助重置密码 MacBook Pro
- c# - 从存储在 listView 中的路径构建树结构