Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我所有<p>的都有一个“A”类。<p>当单击“B”类并将所有其他类重置为“A”类时,我想更改它的类。很容易将<p>s 更改为“B”类,但完全坚持恢复其他人。
<p>
$('p').click(function() { $('p').removeClass('B').addClass('A'); // revert all 'p's to 'A' $(this).removeClass('A').addClass('B'); // 'this' refers to the clicked object });
演示