我需要一个函数在 divs data-page-index 属性更改时运行
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);
$(active.attr('data-page-index')).change(function(){
right.clone( true ). css({'z-index': 5}). fadeIn(2000).appendTo('#right');
left.clone( true ). css({'z-index': 5}). fadeIn(2000).appendTo('#left');
});
我尝试了change()函数,但似乎只适用于输入字段,
$(active.attr('data-page-index')).change(function(){
还有另一种方法可以实现这一目标吗?谢谢。
看来还是要操作DOM来触发事件?如果是这样,您可以操作隐藏输入的值,而不是操作其他元素的数据属性。然后您可以使用change
扳机。
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');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)