jquery - 我如何使用 jquery 修改 Nivo Slider 中的控件导航?

标签 jquery css nivo-slider

我正在尝试自定义 Nivo slider 。我已将这些样式添加到 Nivo slider 。这样,控件 nav 就变成了正方形。

.nivo-control {
    background-color:#eecd0d;
    height:19px;
    width:19px;
    margin-left:5px;
    float:left;
    text-indent:-9999px;
    text-decoration:none;
}

效果很好,所有数字看起来都像正方形。现在我要做的是让每个正方形(总是有四个)有不同的颜色。我所做的是创建 3 个不同的类(第一种颜色由 nivo-control 定义)。这是它的样子:

.second_li {
    background-color:#ab62bc;
}

.third_li {
    background-color:#c491d0;
}

.fourth_li {
    background-color:#d6b2de;
}

问题似乎出在 jQuery 代码上。我正在使用 addClass 将样式动态添加到控件,但它似乎不起作用。

$(function(){
    $(".nivo-controlNav a:nth-child(2)").addClass('second_li);
    $(".nivo-controlNav a:nth-child(3)").addClass('third_li);
    $(".nivo-controlNav a:nth-child(4)").addClass('fourth_li);
});

最佳答案

让我印象深刻的是 jQuery 代码块上的语法高亮显示。请注意第 3 行,在到达下一个引号之前,整行都是红色的。我认为您的代码很好,但是,您忘记在 .addClass() 参数之后添加结束涂层。你的代码应该是这样的

$(function(){
  $(".nivo-controlNav a:nth-child(2)").addClass('second_li');
  $(".nivo-controlNav a:nth-child(3)").addClass('third_li');
  $(".nivo-controlNav a:nth-child(4)").addClass('fourth_li');
});

关于jquery - 我如何使用 jquery 修改 Nivo Slider 中的控件导航?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16310923/

相关文章:

javascript - jQuery 可排序问题

javascript - jQuery if 语句破坏了我的代码

javascript - 数组被覆盖

jquery - 在加载所有图像之前启动 Nivo-slider

jquery - 在 NivoSlider 幻灯片上添加一些带有文本的 div

jquery - 如果最初隐藏,Google 分享按钮无法正确显示

html - 有条件地将 CSS 类应用于 Angular 组件主机

javascript - 单击按钮应检查 Google 表单上的单选输入

javascript - 当插入符号在元素中时,是否有 CSS 选择器?

javascript - Nivo slider 未在 Internet Explorer 中加载(7,8,9)