2022-07-18 16:29:02 +00:00
|
|
|
---
|
|
|
|
id: 60f80e0081e0f2052ae5b505
|
2022-09-28 14:09:47 +00:00
|
|
|
title: 步驟 18
|
2022-07-18 16:29:02 +00:00
|
|
|
challengeType: 0
|
2022-09-28 14:09:47 +00:00
|
|
|
dashedName: step-18
|
2022-07-18 16:29:02 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
|
|
|
指定表單元素的 `type` 屬性對瀏覽器預期表單的數據類型至關重要。 如果未指定 `type`,瀏覽器會使用默認值 `text`。
|
|
|
|
|
|
|
|
給前兩個 `input` 元素設置其 `type` 屬性值爲 `text`,第三個 `type` 屬性值爲 `email`,第四個 `type` 屬性值爲 `password`。
|
|
|
|
|
|
|
|
`email` 類型只允許包含 `@` 以及域名中包含 `.` 的電子郵件。 `password` 類型會屏蔽輸入,如果網站沒有啓用 HTTPS 會警告。
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
|
|
應該給第一個 `input` 添加 `type` 其值爲 `text`。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(document.querySelector('input')?.type, 'text');
|
|
|
|
```
|
|
|
|
|
|
|
|
應該給第二個 `input` 添加 `type` 其值爲 `text`。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(document.querySelectorAll('input')?.[1]?.type, 'text');
|
|
|
|
```
|
|
|
|
|
|
|
|
應該給第三個 `input` 添加 `type` 其值爲 `email`。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(document.querySelectorAll('input')?.[2]?.type, 'email');
|
|
|
|
```
|
|
|
|
|
|
|
|
應該給第四個 `input` 添加 `type` 其值爲 `password`。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert.equal(document.querySelectorAll('input')?.[3]?.type, 'password');
|
|
|
|
```
|
|
|
|
|
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```html
|
|
|
|
<!DOCTYPE html>
|
2022-09-28 14:09:47 +00:00
|
|
|
<html lang="en">
|
2022-07-18 16:29:02 +00:00
|
|
|
<head>
|
2022-09-28 14:09:47 +00:00
|
|
|
<meta charset="UTF-8">
|
2022-07-18 16:29:02 +00:00
|
|
|
<title>Registration Form</title>
|
2022-09-28 14:09:47 +00:00
|
|
|
<link rel="stylesheet" href="styles.css" />
|
2022-07-18 16:29:02 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>Registration Form</h1>
|
|
|
|
<p>Please fill out this form with the required information</p>
|
|
|
|
<form action='https://register-demo.freecodecamp.org'>
|
|
|
|
--fcc-editable-region--
|
|
|
|
<fieldset>
|
2022-09-28 14:09:47 +00:00
|
|
|
<label for="first-name">Enter Your First Name: <input id="first-name" /></label>
|
|
|
|
<label for="last-name">Enter Your Last Name: <input id="last-name" /></label>
|
|
|
|
<label for="email">Enter Your Email: <input id="email" /></label>
|
|
|
|
<label for="new-password">Create a New Password: <input id="new-password" /></label>
|
2022-07-18 16:29:02 +00:00
|
|
|
</fieldset>
|
|
|
|
--fcc-editable-region--
|
|
|
|
<fieldset></fieldset>
|
|
|
|
<fieldset></fieldset>
|
|
|
|
</form>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
```
|
|
|
|
|
|
|
|
```css
|
|
|
|
body {
|
|
|
|
width: 100%;
|
|
|
|
height: 100vh;
|
|
|
|
margin: 0;
|
|
|
|
background-color: #1b1b32;
|
2022-09-28 14:09:47 +00:00
|
|
|
color: #f5f6f7;
|
2022-07-18 16:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
label {
|
2022-09-28 14:09:47 +00:00
|
|
|
display: block;
|
|
|
|
margin: 0.5rem 0;
|
2022-07-18 16:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
```
|