Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/jquery/target-html-elements-with-selectors-using-jquery.md

1.3 KiB
Raw Blame History

id, title, challengeType, forumTopicId, required
id title challengeType forumTopicId required
bad87fee1348bd9bedc08826 使用 jQuery 配合元素选择器选择元素 6 18319
link
https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.0/animate.css

--description--

接下来我们学习document ready function

首先,我们完成第一个 jQuery 语句。所有的 jQuery 函数以$开头,这个符号通常被称为美元符号dollar sign operatorbling

jQuery 通常选取并操作带有选择器selector的 HTML 标签。

例如,如果要所有button有弹性的动画效果,只需在document ready function中添加如下代码即可:

$("button").addClass("animated bounce");

请注意,为了能在编辑器里直接使用,我们已经为你在后台引入了 jQuery 库和 Animate.css 库。因此,你只需要通过 jQuery 给button元素添加bounce类就可以了。

--hints--

用 jQuery 的addClass()方法给button标签添加animatedbounce类。

assert($('button').hasClass('animated') && $('button').hasClass('bounce'));

仅用 jQuery 给标签添加颜色。

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

jQuery 代码应该放在$(document).ready();函数里。

assert(
  code.match(
    /\$\(document\)\.ready\(function.*(\s|\n)*.*button.*.addClass.*\);/g
  )
);

--solutions--