1.1 KiB
1.1 KiB
id | title | challengeType | forumTopicId | required | |||
---|---|---|---|---|---|---|---|
bad87fee1348bd9aeda08826 | 使用 jQuery 配合 id 选择器选择元素 | 6 | 18317 |
|
--description--
你也能通过 id 属性选取标签。
首先,用$("#target3")
选择器选取 id 为target3
的button
标签。
注意,和 CSS 属性一样,在 id 名前需要添加#
。
然后,用 jQuery 的.addClass()
方法添加animated
和fadeOut
类。
下面的代码的效果是使 id 为target6
的button
标签淡出:
$("#target6").addClass("animated fadeOut")
.
--hints--
用 jQuery 的addClass()
方法给id
为target3
的button
标签添加animated
类。
assert($('#target3').hasClass('animated'));
用 jQuery 的addClass()
方法给id
为target3
的标签的类添加fadeOut
类。
assert(
($('#target3').hasClass('fadeOut') || $('#target3').hasClass('fadeout')) &&
code.match(/\$\(\s*.#target3.\s*\)/g)
);
仅用 jQuery 给标签设置类。
assert(!code.match(/class.*animated/g));