Help understanding jQuery button enable/disable code

后端 未结 7 923
孤独总比滥情好
孤独总比滥情好 2020-12-19 19:21

I grabbed this code form JCarousel and just trying to understand these lines below. I\'m new to jQuery and not that great at JavaScript so I am not sure what is jQuery and

7条回答
  •  忘掉有多难
    2020-12-19 19:47

    [n ? 'bind' : 'unbind']
    

    Is an if statement, which can be rewritten as

    if (n) // if n is true
    {
       'bind';
    }
    else
    {
       'unbind';
    }
    

    So if n is true, it would evaluate like this

    this.buttonNext.bind((this.options.buttonNextEvent, this.funcNext))
    

    because [ ] notation is the same as . notation.

    buttonNext[bind] is the same as buttonNext.bind
    

    To summarize what you posted, it checks the states of variables (n and p) which holds the state of the button. If it is enabled, then when activated it disables it, adds the disabled classes, etc. If it's disabled, it sets it to enabled and removes the disabled class.

提交回复
热议问题