freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/jquery/change-the-css-of-an-elemen...

940 B
Raw Blame History

id title challengeType forumTopicId required
bad87fee1348bd9aed908826 使用 jQuery 更改元素的 CSS 6 16776
link
https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css

--description--

我们也能用 jQuery 直接改变 HTML 标签的 CSS。

jQuery 有一个.css()方法,其能改变标签的 CSS。

下面的代码效果是把颜色变蓝:

$("#target1").css("color", "blue");

这与通常的 CSS 声明略有不同,因为这个 CSS 属性和它的值在英文引号里,并且它们用逗号而不是冒号间隔开。

删除你的jQuery选择器并留下空的document ready function

请选择target1并将其颜色变为红色red

--hints--

target1标签应该有红色文本。

assert($('#target1').css('color') === 'rgb(255, 0, 0)');

仅用 jQuery 给标签添加类。

assert(!code.match(/class.*animated/g));

--solutions--