验证| required ="true"/“假" | HTML表格 [英] Validation | required="true" / "false" | HTML form

查看:162
本文介绍了验证| required ="true"/“假" | HTML表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我做一些基本的HTML时,我想知道为什么Sublime Text 3总是将required完整地填充到required=""中.就像我在在线课程中的讲师所说的那样,不必设置required="true"required="false",但是当我将其设置为false时,仍然需要它.

While I was doing some basic HTML I was wondering why Sublime Text 3 always completes required into required="" . Like my Instructor in an online course said it is not necessary to set required="true" or required="false" but when I set it to false it still requires it.

示例代码(即使将其设置为false,也将需要该字段):

example code (it will require the field even if it is set tofalse):

<form>
    <input type="password" name="password" required="false">
    <button>Submit</button>
</form>

我希望您能消除混乱.谢谢您的回答.

I hope you can clear up the confusion. Thanks for every answer.

Farcher

推荐答案

在HTML中,必填属性必须存在(必填字段)或不存在(必填字段 NOT ).存在该属性时,它具有什么 value 无关紧要.

In HTML, the required attribute must be present (the field is required) or absent (the field is NOT required). When the attribute is present, it does not matter what value it has.

必填属性是布尔属性.指定后,该元素是必需的.

The required attribute is a boolean attribute. When specified, the element is required.

元素上存在布尔属性表示真实值,而缺少属性则表示错误值.

The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

关于布尔属性:

没有为其分配值(例如,选中的)的布尔属性隐含地等同于具有为其分配空字符串的值(即,checked =").结果,它代表了真实的价值.

A boolean attribute without a value assigned to it (e.g. checked) is implicitly equivalent to one that has the empty string assigned to it (i.e. checked=""). As a consequence, it represents the true value.

值"true"表示和假"不允许在布尔属性上使用.要表示一个假值,必须完全省略该属性.

The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

一种常见的做法是使用属性的名称作为其:

A common practice is to use the name of the attribute as its value:

<form>
    <input type="password" name="password" required="required"><!-- this input is required -->

    <input type="text" name="sometext"><!-- this input is NOT required -->

    <button>Submit</button>
</form>

这篇关于验证| required ="true"/“假" | HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆