我发现了一个我目前正在尝试修改的jQuery旋转木马。原件可以在http://www.w3schools.com/bootstrap/bootstrap_carousel.asp找到,我正在尝试更改启用轮播指示器。原件是
$(".item0").click(function(){
$("#myCarousel").carousel(0);
});
$(".item2").click(function(){
$("#myCarousel").carousel(1);
});
$(".item3").click(function(){
$("#myCarousel").carousel(2);
});我有比页面提供的更多的图片,我想我可以使用一个泛型类wgi来获取它和item6。我的代码:
$(".wgi").click(function() {
var d = $(this).attr("class").match(/\d+/);
var f = ".item" + d;
alert(d + ", " +f);
$.fn.moveFn = function(){$("#myCarousel").carousel(d)}
$(f).moveFn(d);
alert(d +"b");
}警报起作用了,但我想我构建的函数不起作用。有什么想法吗?
发布于 2015-10-02 03:03:03
如果您只是尝试将轮播移动到索引N,则给定class=itemN。你可以试试这样的东西。您唯一需要考虑的就是0索引,因此请确保您有一个包含'.item0'类的幻灯片
$("[class^=item]").click(function() {
var index = $(this).attr("class").match(/\d+/);
$("#myCarousel").carousel(index);
});https://stackoverflow.com/questions/32894684
复制相似问题