Jquery 切换类不工作

Jquery 切换类不工作,jquery,Jquery,我有一系列的链接可以更改跨度元素的内容。我正在尝试切换它们上的类,以便用户知道他们在配置文件的哪个部分。不过,这似乎并没有改变课程 <div class="profilemenu" style="background: #e2ecfd; width: 100%"> <a style="color: #0b439f;" class="profilemenubutton" id="profile" href="#">Profile</a>&nbsp;

我有一系列的链接可以更改跨度元素的内容。我正在尝试切换它们上的类,以便用户知道他们在配置文件的哪个部分。不过,这似乎并没有改变课程

<div class="profilemenu" style="background: #e2ecfd; width: 100%">
   <a style="color: #0b439f;" class="profilemenubutton" id="profile" href="#">Profile</a>&nbsp;&nbsp; 
   <a class="profilemenubutton" id="clanactivity" href="#">Clan Activity</a>&nbsp;&nbsp; 
   <a class="profilemenubutton" id="recentsessions" href="#">Recent Sessions</a>&nbsp;&nbsp; 
   <a class="profilemenubutton" id="progress" href="#">Progress</a>
</div>

以上信息的集合

echo "$('#profile').click (function () {
$.ajax({
    type: 'GET',
    url: 'includes/profile.php?username=".$username."',
    success: function(msg) {
        $('#info').html(msg);
        $('.active').toggleClass'profilemenubutton');
        $(this).toggleClass('active');
    }
});
});";

为什么在
$(\'a#profile\')
和所有其他选择器中都有反斜杠?php正在响应它,因此我可以在其中传递$username变量。您不需要转义选择器。。去掉“\`好吧,去掉所有选择器中的反斜杠。@rlemon,你是如何得到“`”(也就是说,让反斜杠出现在StackOverflow标记中)的?我不能得到它?尽管看你有限的标记,你的选择器很可能有问题好吧,我正确地更改了类,但它似乎并没有改变样式。这就是CSS的问题。如果类名确实更改了,那么DOM元素将反映附加到该类名的CSS规则。我注意到它将类更改为class=“profilemenubutton active”,因此我的CSS将是.profilemenubutton active{},然后?
.profilemenubutton.active{}
或只是
active{}
检查是否在页面下方过度书写规则。CSS以线性顺序呈现;这意味着如果我写
.red{color:'red';}.red{color:'blue';}
,任何类为
red
的文本节点都将有蓝色文本。
echo "$('#profile').click (function () {
$.ajax({
    type: 'GET',
    url: 'includes/profile.php?username=".$username."',
    success: function(msg) {
        $('#info').html(msg);
        $('.active').toggleClass'profilemenubutton');
        $(this).toggleClass('active');
    }
});
});";