繁体   English   中英

我不明白为什么 HTML 表单不符合要求

[英]I can't figure out why HTML form not meeting requirements

我无法弄清楚我的代码有什么问题 - 星号指出的句子是必需的,下面是我的代码。

  • 正好有一个名称为“pet_name”的输入和一个内容为“Name”的关联标签

  • 正好有一个名称为“pet_type”的“select”元素和一个内容为“Type”的关联标签

 <div> <label for="Name">Name</label> <input type="text" id="name" name="pet_name"> </div> <div> <label for="pet_type">Type</label> <select id="type" name="pet_type"> <option value="Cat">Cat</option> <option value="Dog">Dog</option> <option value="Hamster">Hamster</option> <option value="Other">Other</option> <option value="Zebra">Zebra</option> </select> </div>

标签和元素通过id属性匹配。 此外,它们区分大小写,因此它们需要匹配大写和小写字母。

例如,您可以在这篇 MDN 文章 中找到详细信息。

<div>
  <label for="pet-name">Name</label>
  <input type="text" id="pet-name" name="pet_name">
</div>

<div>
  <label for="pet-type">Type</label>
  <select id="pet-type" name="pet_type">
    <option value="Cat">Cat</option>
    <option value="Dog">Dog</option>
    <option value="Hamster">Hamster</option>
    <option value="Other">Other</option>
    <option value="Zebra">Zebra</option>
  </select>
</div>

for必须是它所引用的元素的id (而不是name )的区分大小写的匹配项。

它应该是:

  <div>
      <label for="name">Name</label>
      <input type="text" id="name" name="pet_name">
  </div>

  <div>
      <label for="type">Type</label>
      <select id="type" name="pet_type">
          <option value="Cat">Cat</option>
          <option value="Dog">Dog</option>
          <option value="Hamster">Hamster</option>
          <option value="Other">Other</option>
          <option value="Zebra">Zebra</option>
      </select>
  </div>

使用 as 作为值它所指的 id

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM