元素按钮不得显示为a元素的后代 [英] The element button must not appear as a descendant of the a element

查看:70
本文介绍了元素按钮不得显示为a元素的后代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助, 验证html5模板时,通过 http://validator.w3.org/出现错误.我收到消息元素按钮一定不能作为元素的后代出现.".我听不懂有人可以帮我解决这个问题吗?

Please help, I am getting error via http://validator.w3.org/ while validating my html5 template. I get the message "The element button must not appear as a descendant of the a element.". I can't understand this. Could anyone help me to solve this?

这是我的代码:

<div class="post-response btn-group btn-group-lg">
   <a href="#"><button type="button" class="btn btn-default"><i class="fa fa-comment"> 5  Comments</i></button></a>
   <a href="#"><button type="button" class="btn btn-default"><i class="fa fa-heart"> 5 Likes</i></button></a>
</div>

推荐答案

W3C验证程序的常见错误是:

The usual error from the W3C validator is:

元素按钮不得显示为a元素的后代

The element button must not appear as a descendant of the a element

这对于您的问题更有意义,因为您有一个按钮是锚点的后代.

This makes more sense for your question, as you have a button that is a descendant of an anchor.

通常,您可以通过简单地设置锚标记样式或将按钮放置在表单元素中来解决此问题:

Normally, you could solve the issue by simply styling your anchor tag, or by placing the button within a form element:

<form style="display: inline" action="http://www.example.com/" method="get">
  <button>Some Call to Action</button>
</form>

但是在您的情况下,我认为您甚至不需要锚点,因为您没有使用HTML链接到任何地方(如果您使用JavaScript附加事件,则可以将这些事件简单地附加到按钮而不是锚点上

But in your case, I don't think you even need the anchors as you aren't linking anywhere using HTML (and if you are attaching events using JavaScript, you could simply attach those events to the button rather than the anchor.

这篇关于元素按钮不得显示为a元素的后代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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