【问题标题】:Why Firexfox and IE cannot open a link (anchor) inside a <button></button> tag. [duplicate]为什么 Firefox 和 IE 无法在 <button></button> 标记内打开链接(锚点)。 [复制]
【发布时间】:2016-12-22 12:06:06
【问题描述】:

为什么 IE 和 Firefox 无法打开按钮标签内的链接,在 chrome 中 它会在同一窗口中打开链接。

例子:

<button type="button"><a href="http://stackoverflow.com">stackoverflow</a></button>

【问题讨论】:

  • 按钮用于启动某些操作。如果您只期望重定向,则可以删除该按钮。如果你想要按钮的外观,你可以使用带有锚标记的样式表来实现它。即使它镀铬,您也不应该这样做。但是,根据 chrome 实现,它可以处理它。这并不意味着你可以这样使用标签。

标签: html


【解决方案1】:

根据 HTML5 规范,按钮内不允许有链接

HTML5 reference from W3

内容模型:短语内容,但必须没有互动 内容后代。

a 是交互式内容的后代

Interactive content description

【讨论】:

    【解决方案2】:

    我不知道为什么,但你应该这样做:

    <a href="http://stackoverflow.com"><button type="button">stackoverflow</button></a>
    

    【讨论】:

      猜你喜欢
      • 2019-01-20
      • 2010-11-26
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 2013-08-16
      • 2014-02-21
      相关资源
      最近更新 更多