首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在函数中传入$( addClass )和addClass

在函数中传入$( addClass )和addClass
EN

Stack Overflow用户
提问于 2017-01-08 03:13:36
回答 1查看 52关注 0票数 0

我目前正在尝试将jQuery传入一个函数,以便稍后可以修改该元素。

代码语言:javascript
复制
$(document).on('pjax:click', function(event) {
    Loader.send($(this));
});

$(document).on('pjax:complete', function() {
    Loader.complete();
});

Loader对象

代码语言:javascript
复制
var Loader = {
    loading: false,
    lastPage: '',
    currentPage: '',
    target: null,

    send: function(_this)
    {
        this.lastPage = window.location.href;
        this.target = _this;
        this.load();
    },

    complete: function()
    {
        this.currentPage = window.location.href;

        // Handle the menu active states
        // Current (new page) url
        var cUrl = this.currentPage.replace('http://', '')
            .replace('https://', '')
            .replace('admin/', '')
            .split('/');

        // Previous page
        var pUrl = this.lastPage.replace('http://', '')
            .replace('https://', '')
            .replace('admin/', '')
            .split('/');

        // If new and old url's are different and they are different sections change the menu
        if(cUrl[1] !== pUrl[1] && this.lastPage !== this.currentPage)
        {
            $(".nav li").removeClass('active');

            this.target.addClass('active');

            console.log('Menu shit');
        }


        this.load();
    },

    load: function() {
        console.log(this);
        $("body").toggleClass('loading');
    }
};

当我使用Loader.send()时,我已经尝试过this$(this),但是我似乎不能在后面的complete方法中向它添加一个类。

有没有一种方法可以通过Loader.send()发送,然后修改它?

EN

回答 1

Stack Overflow用户

发布于 2017-01-08 03:56:50

您正在尝试传递整个文档并在文档级添加类。请提供完整的html,以便我们可以尝试回答它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41525426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档