【问题标题】:What's the correct way to disable a button with html? [duplicate]用html禁用按钮的正确方法是什么? [复制]
【发布时间】:2012-07-25 01:50:20
【问题描述】:

可能重复:
What's the proper way to add selected and related attributes to inputs?
Correct value for disabled attribute

我有以下几点:

    <button id="refreshLink" class="blue" type="button" title="Refresh Topic Grid"
        data-entity="Topic"
        data-href="/Admin/Contents/Reference">
        <span class="center-icon sprite-arrow-circle"></span></button>

我看到了很多不同的方法来禁用它。

disabled=true
disabled=disabled
disabled

执行此操作的正确方法是什么?我越来越糊涂了。

【问题讨论】:

  • 哪个版本的HTML?我认为 html5 可以有不同的语法。您喜欢的网络编辑器是否会建议您正确的语法(我使用 Visual Studio,这是它的功能之一)。

标签: html


【解决方案1】:

后两个(disabled=disableddisabled)都是正确的。您可以根据个人喜好选择使用哪一种。 disabled 属性是一个布尔属性,can not contain the value true (although it will still work)

【讨论】:

    【解决方案2】:
    disabled=disabled 
    

    根据我的理解是正确的功能

    如果你给 disabled=xxx 即)它也可以,但 disabled=disabled 是正确的

    【讨论】:

      【解决方案3】:

      disabled="disabled" 和disabled 是一回事。

      浏览器都很好理解。

      我从未见过disabled=true,因此请考虑一下这可能不是一个好习惯。

      已编辑。

      前言,W3C 建议是:

      <button disabled>
      

      来源:http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1

      (保留历史的坏链接:http://www.w3schools.com/tags/att_button_disabled.asp

      【讨论】:

      • disabled=true 语法无效 - 检查验证器。
      • 对不起。我在
      • w3schools.com不是W3C,一般都是errors
      • @Inkbug 你是对的(再次)。同一个评论有2个错误。 -_-' 我已经用 w3c 替换了 w3scools 链接。
      • 这样更好。删除了我的反对票。
      猜你喜欢
      • 1970-01-01
      • 2018-05-10
      • 1970-01-01
      • 2020-09-09
      • 2012-05-27
      • 2019-09-30
      • 2020-12-04
      • 1970-01-01
      • 2017-04-24
      相关资源
      最近更新 更多