如果您的链接与面板的顺序相同,您可以执行以下操作:
$('.link').on('click', function() {
$('#carousel').carousel($(this).index());
});
如果您只有一个链接,只需对其进行硬编码:
var i = 2; //index of the panel
$('#link').on('click', function() {
$('#carousel').carousel(i);
});
来自文档:
Methods:
carousel(options)
Initializes the carousel with an optional options object and starts cycling through items.
$('.carousel').carousel({
interval: 2000
})
.carousel('cycle')
Cycles through the carousel items from left to right.
.carousel('pause')
Stops the carousel from cycling through items.
.carousel(number)
Cycles the carousel to a particular frame (0 based, similar to an array).
.carousel('prev')
Cycles to the previous item.
.carousel('next')
Cycles to the next item.