javascript - 在 :nth-child( X ) won't work 中插入 VAL

标签 javascript jquery jquery-selectors

为什么我不能在底部使用 SlideNumber...?? 我试图将 var SlideNumber = 3; 更改为 SlideNumber = 3; 但老实说,我在黑暗中摸索。

if(window.location.hash != '') {
    var SlideNumber = 3;
    $('.slideshow').cycle({
        fx: 'blindY', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        speed:  700,
        cleartype:  1,
        startingSlide: $(window.location.hash).index(),
        timeout: 3000,
          after: function(curr,next,opts) {             
            $("#menu ul li:nth-child(SlideNumber)").addClass("active");
            ready = true;
          } 

    });

提前谢谢你。

最佳答案

要补充一点,您可以通过使用 .eq 来避免串联并稍微提高性能。过滤方法(采用从零开始的索引):

$("#menu ul li").eq(slideNumber-1).addClass("active");

关于javascript - 在 :nth-child( X ) won't work 中插入 VAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5262115/

相关文章:

javascript - 更改每个图像源以加载较小的版本

javascript - "key in obj"当 obj 是一个函数?

c# - 任何用于 .NET/C# 的 Javascript 引擎?

javascript - 当我将组件从无状态转换为有状态时,数据没有及时读取;

javascript - 如何拦截onclick事件

jquery - 为什么 jquery 需要一个 ui 对话框的选择器

javascript - MS Graph 创建在线 session : "onlinemeeting cannot be null."

jquery - 从上到下过渡不透明文本

jquery - jQuery .not 选择器可以与 .delegate 一起使用吗?

jQuery .show();函数不显示之前隐藏的所有元素