gpt4 book ai didi

jquery - 使用 jquery 嵌入 CSS

转载 作者:太空宇宙 更新时间:2023-11-03 23:29:38 25 4
gpt4 key购买 nike

我正在尝试使用 jquery 将 css 嵌入到 HTML 正文中。 CSS 看起来像

.a .a101{fill:rgb(165,0,38)}
.a .a102{fill:rgb(215,48,39)}

我尝试了以下方法,但无法识别:

$(".a .a101").css({
fill : 'rgb(165,0,38)'
});
$(".a .a102").css({
fill : 'rgb(215,48,39)'
});

请问您能告诉我正确的做法吗?

-问候

最佳答案

首先,我认为你应该从仔细阅读开始the jQuery .css() method documentation .

然后,其实很简单,你只是忘记了引号:.css({'fill': 'red'})

仅供引用,您可以在 vanilla JS 中轻松完成:

document.querySelectorAll('#idForThisExample').style.fill = 'silver';

编辑: Here is a working JS fiddle containing a function to loop through DOM elements .你会有很好的表现,这是很好的训练。

关于jquery - 使用 jquery 嵌入 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25757120/

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