我可以嵌套一个 <button><a>内的元素使用 HTML5? [英] Can I nest a <button> element inside an <a> using HTML5?

查看:19
本文介绍了我可以嵌套一个 <button><a>内的元素使用 HTML5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做以下事情:

 <a href="www.stackoverflow.com">
   <button disabled="disabled" >ABC</button>
 </a>  

这很好用,但我收到一个 HTML5 验证错误,提示元素‘按钮’不得嵌套在元素‘按钮’中.

This works good but I get a HTML5 validation error that says "Element 'button' must not be nested within element 'a button'.

谁能给我建议我应该做什么?

Can anyone give me advice on what I should do?

推荐答案

,根据 来自 W3C 的 HTML5 规范文档:

内容模型:透明,但必须没有交互式内容后代.

a 元素可以环绕整个段落、列表、表格等,甚至整个部分,只要其中没有交互内容(例如按钮或其他链接).

The a element may be wrapped around entire paragraphs, lists, tables, and so forth, even entire sections, so long as there is no interactive content within (e.g. buttons or other links).

换句话说,您可以在 中嵌套任何元素,但以下内容除外:

In other words, you can nest any elements inside an <a> except the following:

(如果存在 controls 属性)