Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在Bootstrap';旋转木马?_Jquery_Twitter Bootstrap_Carousel - Fatal编程技术网

Jquery 如何在Bootstrap';旋转木马?

Jquery 如何在Bootstrap';旋转木马?,jquery,twitter-bootstrap,carousel,Jquery,Twitter Bootstrap,Carousel,使用Bootstrap的旋转木马,我希望能够单击链接并跳到旋转木马中的特定幻灯片。我该怎么做?我必须添加什么jquery 这是我的html(它不起作用,但让你知道我想做什么): ... 如果链接与面板的顺序相同,则可以执行以下操作: $('.link').on('click', function() { $('#carousel').carousel($(this).index()); }); 如果只有一个链接,只需硬编码即可: var i = 2; //index of the p

使用Bootstrap的旋转木马,我希望能够单击链接并跳到旋转木马中的特定幻灯片。我该怎么做?我必须添加什么jquery

这是我的html(它不起作用,但让你知道我想做什么):


...

如果链接与面板的顺序相同,则可以执行以下操作:

$('.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.

对我来说,指定的脚本化方法不起作用,但是基于另一个示例,我能够使用数据标记使其起作用

<a data-target="#myCarousel" data-slide-to="0" href="#">First</a>


请注意,
数据幻灯片到
索引是基于0的,这是在Bootstrap 4上测试的

我尝试了这两种方法。我将jquery添加到bootstrap.js文件中,并将“link”更改为“panel”,但它不起作用。我也试着把它放进去,我让它工作了。答案可以在这里找到:非常好,不需要JavaScript,这正是我想要的。
<a data-target="#myCarousel" data-slide-to="0" href="#">First</a>