jQuery event on attribute change

后端 未结 1 945
长情又很酷
长情又很酷 2021-02-13 18:25

I need a function to run when a divs data-page-index attribute changes

  var active = $(\'.swipeview-active\'),
      dpi =  parseInt(active.attr(\'data-page-ind         


        
1条回答
  •  遇见更好的自我
    2021-02-13 18:47

    It seems that you still have to manipulate the DOM to trigger the event? If so, you can manipulate a hidden input's value instead of manipulating other elements' data attributes. Then you can use the change trigger.

      var active = $('.swipeview-active'),
          dpi =  parseInt(active.attr('data-page-index')),
          left = $('[data-page-index="' +prev+ '"]').children("img").eq(0),
          right = $('[data-page-index="' +next+ '"]').children("img").eq(0),
          dpiInput = $('.swipeview-active input:hide');
    
      dpiInput.change(function(){
        right.clone( true ). css({'z-index': 5}). fadeIn(2000).appendTo('#right');
        left.clone( true ). css({'z-index': 5}). fadeIn(2000).appendTo('#left');
      });
    

    trigger:

    $('.swipeview-active input:hide').val(1).trigger('change');
    

    0 讨论(0)
提交回复
热议问题