【问题标题】:Can the name attribute of the input of the HTML form not have the same value as the type attribute?HTML表单输入的name属性不能和type属性的值不一样吗?
【发布时间】:2018-10-11 04:30:47
【问题描述】:

HTML表单输入的name属性不能和type属性值相同吗?

我发现当我使用输入的名称和输入的类型作为同一个属性时,有些函数会没有字。

【问题讨论】:

  • type 可以是 datetextpasswordname 字段可以是任何内容。

标签: html forms


【解决方案1】:

type 属性必须是有效的可用值之一,例如文本或密码。

name 属性是你定义的。

当它们的值相同时,有时它们对你不起作用的可能原因是,你可能给类型属性赋予了一个对其无效的值。

例如:

<input type="coupon" name="coupon">    <!-- This won't work, type "coupon" doesn't exist -->
<input type="password" name="password"> <!-- This will work -->
<input type="text" name="coupon"> <!-- This will work -->

第二个会起作用,因为密码是 type 属性的有效值。 第一个不起作用,因为没有“优惠券”这样的输入类型。所以需要将类型改为“文本”。

这是一个容易犯的错误,所以我建议检查一下。

【讨论】:

    猜你喜欢
    • 2017-04-16
    • 1970-01-01
    • 2014-12-20
    • 2015-01-20
    • 2013-10-07
    • 2011-06-20
    • 2014-03-28
    • 1970-01-01
    • 2014-01-11
    相关资源
    最近更新 更多