2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: bad87fee1348bd9aec908853
|
|
|
|
title: Add id Attributes to Bootstrap Elements
|
|
|
|
challengeType: 0
|
2020-09-07 16:17:39 +08:00
|
|
|
forumTopicId: 16639
|
|
|
|
localeTitle: 给 Bootstrap 元素添加id属性
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-09-07 16:17:39 +08:00
|
|
|
<section id='description'>
|
|
|
|
回忆一下,除了可以给元素添加 class 属性,我们还可以给元素设置 <code>id</code> 属性。
|
|
|
|
每个指定元素的 id 都是唯一的,并且在每个页面中都只能使用一次。
|
|
|
|
让我们为每个 class 为 <code>well</code> 的 <code>div</code> 元素添加一个唯一的 id。
|
|
|
|
记住,你可以这样给一个元素设置 ID。
|
|
|
|
<code><div class="well" id="center-well"></code>
|
|
|
|
把左边 well 的 ID 设置为 <code>left-well</code>。右边的 well 的 ID 设置为 <code>right-well</code>。
|
|
|
|
</section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
2020-09-07 16:17:39 +08:00
|
|
|
<section id='instructions'>
|
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
2020-09-07 16:17:39 +08:00
|
|
|
- text: 把左边的 <code>well</code> 的 ID 设置为 <code>left-well</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert($(".col-xs-6").children("#left-well") && $(".col-xs-6").children("#left-well").length > 0);
|
2020-09-07 16:17:39 +08:00
|
|
|
- text: 把右边的 <code>well</code> 的 ID 设置为 <code>right-well</code>。
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert($(".col-xs-6").children("#right-well") && $(".col-xs-6").children("#right-well").length > 0);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='html-seed'>
|
|
|
|
|
|
|
|
```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>
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
2020-09-07 16:17:39 +08:00
|
|
|
```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>
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2020-09-07 16:17:39 +08:00
|
|
|
</section>
|