douba3943 2018-11-08 11:16
浏览 136

jquery - 模态分页。 上一页/下一页

I have some dynamic modals that appear after a click on a div. I want to join those modals through two prev/next arrows and let people, who click on the arrows go between the modals without having to close the current modal and open the next one.

click here to see what I'm working on. if you click on the arrow I need to go to the next prev popup modal.

So the arrows don't work

Here's the code: [

    var countModal =0;
    // Get the button that opens the modal
    $('.plan-wrapper').on('click', function() {
        var id = $(this).data('id');
        console.log($(this).data('count'));
        $('#myModal_'+id).css('display', 'flex');
        countModal =  $(this).data('count');
        
    })        

    // Get the button that opens the modal     
    $('.chiudi_dimensione').on('click', function() {
        var id = $(this).data('id');
        $('#myModal_'+id).hide();
    })        

    $listModal = $('.mymodal');        
    console.log($listModal);
    
    $('.freccia-indietro').on('click', function(value){  
        console.log($listModal[countModal]);
        $listModal[countModal].style.display = 'none';
        countModal = countModal -1;
        if(countModal<0){
            coutModal=$listModal.count;
        }                    
        $listModal[countModal].style.display = 'flex';
    })
    
    $('.freccia-indietro').on('click', function(value){
        countModal = countModal +1;
        if(countModal>$listModal.count){
            coutModal=0;
        }
    })
    
<script src="https://code.jquery.com/jquery-3.3.1.min.js" type="text/javascript"></script>
    
 <div class="plan-wrapper" data-id='<?php echo $id; ?>'>
 
 <div style="opacity:1" id="myModal_<?php echo $id; ?>" class="lightbox_wrapper_dimensione">
      <div data-id='<?php echo $id; ?>' class="chiudi_dimensione">X</div>
      <div class="freccia-indietro"></div>
      <div class="freccia-avanti"></div>
</div> 

</div>
  • 写回答

1条回答 默认 最新

  • dongying6896 2018-11-08 11:54
    关注

    1 no class myModal seems to be present in your html maybe you should give class=myModal attribute to all your modals to retrive'em via $listModal = $('.mymodal');

    2 you have a typo coutModal instead of countModal

    3 to get the length of jquery collection use length not count replace $listModal.count; with $listModal.length;

    e facci sapere ;)

    评论

报告相同问题?

悬赏问题

  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图