编辑:如果您只是在单击按钮时需要它,而不是因为它的auto
功能,您可以.delegate()
在.carousel
它可用时放置 a 以侦听元素click
上的事件。'a[role=button]'
$('.carousel').delegate('a[role=button]', 'click', function() {
// Because a button in the carousel was clicked, we know that
// one of the elements received the .active class. So we just
// need to find it.
var $activeButton = $(this).closest('.carousel').find('.active');
// Not sure how the .red class from your question factors in, but you
// can test the $activeButton to see if it has that class
if( $activeButton.hasClass('red') ) {
$('#formred').attr('checked', 'checked');
}
});
同样,这仅适用于按钮上的点击事件,而不是设置为auto
旋转。不确定这是否是您所追求的。
如果需要,有一个插件livequery
可以通过 jQuery 运行 DOM 修改代码。
http://brandonaaron.net/code/livequery/docs
$('.someClass').livequery( function() {
// your code
});
如果您传递第二个函数参数,它将在删除类(或元素)时运行。
$('.someClass').livequery( function() {
// your code when adding
}, function() {
// your code when removing
});