Files
freeCodeCamp/curriculum/challenges/chinese/03-front-end-libraries/bootstrap/add-id-attributes-to-bootstrap-elements.md
2021-03-22 06:52:28 -07:00

94 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: bad87fee1348bd9aec908853
title: 给 Bootstrap 元素添加 id 属性
challengeType: 0
forumTopicId: 16639
dashedName: add-id-attributes-to-bootstrap-elements
---
# --description--
回忆一下,除了可以给元素添加 class 属性,我们还可以给元素设置 `id` 属性。
每个元素的 id 都必须是唯一的,并且在一个页面中只能使用一次。
让我们为每个 class 为 `well``div` 元素添加一个唯一的 id。
记住,可以这样给一个元素设置 id
```html
<div class="well" id="center-well">
```
给左边的块设置 id 为 `left-well`。 给右边的块设置 id 为 `right-well`
# --hints--
左边的 `well` 的 id 应为 `left-well`
```js
assert(
$('.col-xs-6').children('#left-well') &&
$('.col-xs-6').children('#left-well').length > 0
);
```
右边的 `well` 的 id 应为 `right-well`
```js
assert(
$('.col-xs-6').children('#right-well') &&
$('.col-xs-6').children('#right-well').length > 0
);
```
# --seed--
## --seed-contents--
```html
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<div class="well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
<div class="col-xs-6">
<div class="well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
</div>
</div>
```
# --solutions--
```html
<div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row">
<div class="col-xs-6">
<div class="well" id="left-well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
<div class="col-xs-6">
<div class="well" id="right-well">
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
<button class="btn btn-default target"></button>
</div>
</div>
</div>
</div>
```