我想用jQuery脚本切换一些内联CSS,但是我不能用类来做,因为我动态得到了padding-top的值,这里是函数:
$('.button').click(function(){
$(this).toggleClass('active');
});
var tagsHeight = $('span').outerHeight();
$(".button").click(function (){
if ($(this).is('active')) {
$(".change").css('padding-top', '0');
}
else if ($(this).not('active')) {
$(".change").css('padding-top', tagsHeight);
}
});
Run Code Online (Sandbox Code Playgroud)
这里有一个例子:https://jsfiddle.net/o1pbwfuo/
我真的不明白为什么这不能正常工作......
谢谢 !