gpt4 book ai didi

javascript - 更改现有的 css 属性并通过删除或添加 css 元素来使用它

转载 作者:太空宇宙 更新时间:2023-11-04 12:14:13 24 4
gpt4 key购买 nike

我有一个关于更改现有 css 属性的问题。我在我的 html 代码中使用 Jquery。

我想知道如何更改现有的 css 类属性并将更改后的类应用于其他元素。

感谢您关心我的问题。

★ css代码示例

.AccentColor{color:#fff;background:#000;}

★ javascript

<script>
$(document).ready(function(){
$('.AccentColor').css('background','yellow');
$('#target').addClass('AccentColor');
});
</script>

★ html

<p id="target"> still background color is #000, not yellow.</p>

最佳答案

您应该从传递给 addClass 函数的类名中删除点

$(selector).addClass("classname")

确保您使用的是正确的类名。在你的情况下 AccentColor

关于javascript - 更改现有的 css 属性并通过删除或添加 css 元素来使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28837913/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com