103 lines
2.9 KiB
Markdown
103 lines
2.9 KiB
Markdown
|
---
|
||
|
id: 62ff8e998d3e7eae14d6ae3b
|
||
|
title: 步驟 28
|
||
|
challengeType: 0
|
||
|
dashedName: step-28
|
||
|
---
|
||
|
|
||
|
# --description--
|
||
|
|
||
|
按照無障礙最佳實踐,將第二個 `fieldset` 內的 `input` 元素和 `label` 元素關聯起來。
|
||
|
|
||
|
使用 `personal-account`、`business-account` 和 `terms-and-conditions` 作爲對應的 `id` 屬性的值。
|
||
|
|
||
|
# --hints--
|
||
|
|
||
|
第一個 `input` 元素的 `id` 應該爲 `personal-account`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) input')?.[0]?.matches('#personal-account'))
|
||
|
```
|
||
|
|
||
|
第二個 `input` 元素的 `id` 應該爲 `business-account`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) input')?.[1]?.matches('#business-account'))
|
||
|
```
|
||
|
|
||
|
第三個 `input` 元素的 `id` 應該爲 `terms-and-conditions`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) input')?.[2]?.matches('#terms-and-conditions'))
|
||
|
```
|
||
|
|
||
|
第一個 `label` 元素的 `for` 屬性應該爲 `personal-account`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) label')?.[0]?.matches('label[for="personal-account"]'))
|
||
|
```
|
||
|
|
||
|
第二個 `label` 元素的 `for` 屬性應該爲 `business-account`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) label')?.[1]?.matches('label[for="business-account"]'))
|
||
|
```
|
||
|
|
||
|
第三個 `label` 元素的 `for` 屬性應該爲 `terms-and-conditions`。
|
||
|
|
||
|
```js
|
||
|
assert(document.querySelectorAll('fieldset:nth-of-type(2) label')?.[2]?.matches('label[for="terms-and-conditions"]'))
|
||
|
```
|
||
|
|
||
|
# --seed--
|
||
|
|
||
|
## --seed-contents--
|
||
|
|
||
|
```html
|
||
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<title>Registration Form</title>
|
||
|
<link rel="stylesheet" href="styles.css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1>Registration Form</h1>
|
||
|
<p>Please fill out this form with the required information</p>
|
||
|
<form action='https://register-demo.freecodecamp.org'>
|
||
|
<fieldset>
|
||
|
<label for="first-name">Enter Your First Name: <input id="first-name" type="text" required /></label>
|
||
|
<label for="last-name">Enter Your Last Name: <input id="last-name" type="text" required /></label>
|
||
|
<label for="email">Enter Your Email: <input id="email" type="email" required /></label>
|
||
|
<label for="new-password">Create a New Password: <input id="new-password" type="password" pattern="[a-z0-5]{8,}" required /></label>
|
||
|
</fieldset>
|
||
|
--fcc-editable-region--
|
||
|
<fieldset>
|
||
|
<label><input type="radio" name="account-type" /> Personal Account</label>
|
||
|
<label><input type="radio" name="account-type" /> Business Account</label>
|
||
|
<label><input type="checkbox" required /> I accept the terms and conditions</label>
|
||
|
</fieldset>
|
||
|
--fcc-editable-region--
|
||
|
<fieldset></fieldset>
|
||
|
<input type="submit" value="Submit" />
|
||
|
</form>
|
||
|
</body>
|
||
|
</html>
|
||
|
```
|
||
|
|
||
|
```css
|
||
|
body {
|
||
|
width: 100%;
|
||
|
height: 100vh;
|
||
|
margin: 0;
|
||
|
background-color: #1b1b32;
|
||
|
color: #f5f6f7;
|
||
|
}
|
||
|
|
||
|
label {
|
||
|
display: block;
|
||
|
margin: 0.5rem 0;
|
||
|
}
|
||
|
|
||
|
```
|