简体   繁体   English

如何将一个类更改为元素的nodeValue? 我究竟做错了什么?

[英]How to change a class to the nodeValue of the element? What am I doing wrong?

I want to change the effect (class) of my scroller to the effect on the button a user clicks. 我想将滚动条的效果(类)更改为用户单击按钮上的效果。 Here's my code: 这是我的代码:

var scroller=$('#main ul.stroll'); --> I know this is right.. just a var reference

function effectSelect(e){

    var target = $(e.currentTarget);

    $(target).click(function(){
        var effectName=target.nodeValue;
        var effect='stroll ' + effectName;
        scroller.removeClass();
        scroller.addClass(effect);
    })
}

It worked at a certain point then suddenly stopped working. 它在某个时间点工作,然后突然停止工作。 There are no errors in the console when I run it. 运行控制台时,它没有错误。 What am I doing wrong? 我究竟做错了什么? Let me know if you need more info 让我知道您是否需要更多信息

Figured it out finally. 终于明白了。 Hope this helps anyone in a similar situation! 希望这对遇到类似情况的人有所帮助!

function init(event) {

    stroll.bind($scroller);

    $('.nav li').on('click', function(event){
        var target = $(event.target);
        var effectName = target.text();
        var effect = 'stroll ' + effectName;
        $scroller.removeClass();
        $scroller.addClass(effect);

        console.log($scroller.attr('class'))
    });

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM