【问题标题】:Validation on fieldset. The fieldset is inside the form and has inputs outside验证字段集。字段集在表单内部,在外部有输入
【发布时间】:2009-10-02 20:11:08
【问题描述】:
<form id="youtube-form" method="post" action="">

  <label for="searchField" id="label-youtube-id">YouTube ID:</label>
  <input type="text" id="searchField" name="videoid" class="search-field" />

  <fieldset id="outputFieldset">
    <legend>Output format:</legend>
        <label for="flv">FLV</label>
        <input type="radio" id="flv" name="format" class="radio-button" value="flv" />

        <label for="avi">AVI</label>
        <input type="radio" id="avi" name="format" class="radio-button" value="avi" />

        <label for="mp3">MP3</label>
        <input type="radio" id="mp3" name="format" class="radio-button" value="mp3" />
  </fieldset>

  <input id="youtube-submit" type="submit" name="submit" value="Submit" />

</form>

这段代码有什么问题?验证时似乎出现错误。 (三个也是)

第 21 行,第 49 列:文档类型 此处不允许元素“标签”; 缺少“ins”、“del”、“h1”之一, “h2”、“h3”、“h4”、“h5”、“h6”、“p”、 “div”、“address”、“fieldset”开始标签

是因为我需要添加更多的字段集,还是我做错了什么?

非常感谢任何帮助:)

【问题讨论】:

    标签: html xhtml forms fieldset


    【解决方案1】:

    inputlabel 元素不允许作为 form 元素的子元素。

    ins, del, h1, h2, h3, h4, h5, h6, p, address, @98654334@, @9867654333允许作为子元素,也允许将 inputlabel 元素作为它们的子元素(尽管大多数在语义上不合适)。

    【讨论】:

    • 谢谢 :) 现在我明白了这个问题。但是为什么您在互联网上看到这么多指南完全省略了字段集?
    • 在 HTML 的过渡版本中允许输入和标签作为表单的子元素。我们现在已经远远超过了过渡期。
    【解决方案2】:

    标签和输入应该在字段集中。或者创建第二个/第三个文件集以分别封装它们。

    例如:

    <form id="youtube-form" method="post" action="">
    
    
     <fieldset id="youtube">
      <label for="searchField" id="label-youtube-id">YouTube ID:</label>
      <input type="text" id="searchField" name="videoid" class="search-field" />
     </fieldset>
    
      <fieldset id="outputFieldset">
        <legend>Output format:</legend>
            <label for="flv">FLV</label>
            <input type="radio" id="flv" name="format" class="radio-button" value="flv" />
    
            <label for="avi">AVI</label>
            <input type="radio" id="avi" name="format" class="radio-button" value="avi" />
    
            <label for="mp3">MP3</label>
            <input type="radio" id="mp3" name="format" class="radio-button" value="mp3" />
      </fieldset>
    
     <fieldset id="submit">
      <input id="youtube-submit" type="submit" name="submit" value="Submit" />
     </fieldset>
    </form>
    

    【讨论】:

    • 感谢您提供正确的代码供我使用。我从中吸取了教训。
    猜你喜欢
    • 2021-11-02
    • 2021-11-30
    • 2017-06-15
    • 2023-03-14
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多