【问题标题】:Are you allowed to have an input without a value?您是否允许输入没有值?
【发布时间】:2010-10-16 06:54:20
【问题描述】:

以下是否允许?

<input type="hidden" name="field" />

【问题讨论】:

    标签: html forms input


    【解决方案1】:

    在隐藏字段中很好。仅在复选框和单选输入中需要。它永远不能用文件输入来指定。见http://www.w3schools.com/TAGS/att_input_value.asp

    【讨论】:

    【解决方案2】:

    XHTML 1.1 schema 表示value强制性的:

     <xs:attributeGroup name="xhtml.input.attlist">
        <xs:attributeGroup ref="xhtml.Common.attrib"/>
        <xs:attribute name="type" type="xhtml.InputType.class" default="text"/>    
        <xs:attribute name="name" type="xh11d:CDATA"/>
        <xs:attribute name="value" type="xh11d:CDATA"/>
        <xs:attribute name="checked">
          <xs:simpleType>
            <xs:restriction base="xs:NMTOKEN">
              <xs:enumeration value="checked"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="size" type="xh11d:Number"/>
        <xs:attribute name="maxlength" type="xh11d:Number"/>
        <xs:attribute name="src" type="xh11d:URI"/>
        <xs:attribute name="tabindex" type="xh11d:Number"/>    
        <xs:attribute name="accesskey" type="xh11d:Character"/>
      </xs:attributeGroup>
    

    【讨论】:

    • 问题有标签“html”,与xhtml 1.1不同。我知道迂腐,但任何积极使用 xhtml 1.1 的人都应该精通上述迂腐。
    • 问题也有 作为 ,所以显然无效的 HTML 而是 XML ...
    【解决方案3】:

    是的,表单输入由您控制以满足您的要求,只要它们是格式良好且有效的 xhtml。

    不过,这似乎毫无意义。

    【讨论】:

    • 保存转移 :P 虽然很小,但在这种情况下,每次调用都会丢失 20 个 value="",并且这个调用可以为一个用户进行 1000 次。节省的费用可能很小,但会使代码更简洁......虽然不太明显。
    猜你喜欢
    • 2023-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-30
    • 2011-06-30
    • 1970-01-01
    • 2013-09-25
    • 1970-01-01
    相关资源
    最近更新 更多