我目前正在尝试将jQuery传入一个函数,以便稍后可以修改该元素。
$(document).on('pjax:click', function(event) {
Loader.send($(this));
});
$(document).on('pjax:complete', function() {
Loader.complete();
});Loader对象
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()发送,然后修改它?
发布于 2017-01-08 03:56:50
您正在尝试传递整个文档并在文档级添加类。请提供完整的html,以便我们可以尝试回答它。
https://stackoverflow.com/questions/41525426
复制相似问题