freeCodeCamp/curriculum/challenges/chinese-traditional/14-responsive-web-design-22/learn-html-forms-by-buildin.../60f80e0081e0f2052ae5b505.md

2.0 KiB

id title challengeType dashedName
60f80e0081e0f2052ae5b505 步驟 16 0 step-16

--description--

指定表單元素的 type 屬性對瀏覽器預期表單的數據類型至關重要。 如果未指定 type,瀏覽器會使用默認值 text

給前兩個 input 元素設置其 type 屬性值爲 text,第三個 type 屬性值爲 email,第四個 type 屬性值爲 password

email 類型只允許包含 @ 以及域名中包含 . 的電子郵件。 password 類型會屏蔽輸入,如果網站沒有啓用 HTTPS 會警告。

--hints--

應該給第一個 input 添加 type 其值爲 text

assert.equal(document.querySelector('input')?.type, 'text');

應該給第二個 input 添加 type 其值爲 text

assert.equal(document.querySelectorAll('input')?.[1]?.type, 'text');

應該給第三個 input 添加 type 其值爲 email

assert.equal(document.querySelectorAll('input')?.[2]?.type, 'email');

應該給第四個 input 添加 type 其值爲 password

assert.equal(document.querySelectorAll('input')?.[3]?.type, 'password');

--seed--

--seed-contents--

<!DOCTYPE html>
<html>
  <head>
    <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'>
--fcc-editable-region--
      <fieldset>
        <label>Enter Your First Name: <input /></label>
        <label>Enter Your Last Name: <input /></label>
        <label>Enter Your Email: <input /></label>
        <label>Create a New Password: <input /></label>
      </fieldset>
--fcc-editable-region--
      <fieldset></fieldset>
      <fieldset></fieldset>
    </form>
  </body>
</html>
body {
  width: 100%;
  height: 100vh;
  margin: 0;
  background-color: #1b1b32;
    color: #f5f6f7;
}

label {
    display: block;
    margin: 0.5rem 0;
}