freeCodeCamp/curriculum/challenges/chinese/01-responsive-web-design/basic-html-and-html5/create-a-set-of-checkboxes....

3.3 KiB

id title challengeType videoUrl localeTitle
bad87fee1348bd9aedf08835 Create a Set of Checkboxes 0 创建一组复选框

Description

表单通常使用checkboxes来表示可能有多个答案的问题。复选框是一种类型的input您的每一个复选框可以嵌套自身的内label元素。通过将input元素包装在label元素内部,它将自动将复选框输入与其周围的标签元素相关联。所有相关的复选框输入应具有相同的name属性。通过在label元素上设置for属性以匹配关联input元素的id属性,最佳做法是明确定义复选框input与其对应label之间的关系。这是一个复选框的示例: <label for="loving"><input id="loving" type="checkbox" name="personality"> Loving</label>

Instructions

在表单中添加一组三个复选框。每个复选框应嵌套在自己的label元素中。这三者都应该分享personalityname属性。

Tests

tests:
  - text: 您的页面应该有三个复选框元素。
    testString: 'assert($("input[type="checkbox"]").length > 2, "Your page should have three checkbox elements.");'
  - text: 三个复选框元素中的每一个都应嵌套在自己的<code>label</code>元素中。
    testString: 'assert($("label > input[type="checkbox"]:only-child").length > 2, "Each of your three checkbox elements should be nested in its own <code>label</code> element.");'
  - text: 确保每个<code>label</code>元素都有一个结束标记。
    testString: 'assert(code.match(/<\/label>/g) && code.match(/<label/g) && code.match(/<\/label>/g).length === code.match(/<label/g).length, "Make sure each of your <code>label</code> elements has a closing tag.");'
  - text: 为您的复选框提供<code>personality</code>的<code>name</code>属性。
    testString: 'assert($("label > input[type="checkbox"]").filter("[name="personality"]").length > 2, "Give your checkboxes the <code>name</code> attribute of <code>personality</code>.");'

Challenge Seed

<h2>CatPhotoApp</h2>
<main>
  <p>Click here to view more <a href="#">cat photos</a>.</p>

  <a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."></a>

  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
  <form action="/submit-cat-photo">
    <label for="indoor"><input id="indoor" type="radio" name="indoor-outdoor"> Indoor</label>
    <label for="outdoor"><input id="outdoor" type="radio" name="indoor-outdoor"> Outdoor</label><br>
    <input type="text" placeholder="cat photo URL" required>
    <button type="submit">Submit</button>
  </form>
</main>

Solution

// solution required