所以我有一个toggleClass
来改变一些div的类(它改变背景),当一个div被按下时。 当另一个div被按下时,我需要bg变回正常状态,并关闭".subtitle"
,并切换您按下的新div。jQuery toggleClass - 返回普通类?
现在,关闭和打开功能工作正常,但背景没有改变。
标准类是.title
,我也有一个.title.close
其中只包含其他背景。
我可以在这里得到一些帮助吗?
CSS:
.title: contains the normal bg
.title.open: contains the "open" bg
.title.close: contains the bg of title(the normal bg)
jQuery
$(document).ready(function()
{
$(".title").click(function()
{
var $element = $(this);
//What I've tried
$('open').toggleClass('');
$('.subtitle').hide(500);
//This is changing the bg, and show the ".subtitle" you've pressed
$element.toggleClass('open');
$element.children('.subtitle').toggle(500);
});
});
这是正确的选择:'$('open')。toggleClass('');'?或者你应该使用$('。open')。 – 2013-03-07 09:14:32