错误:看到一个开始标记但是已经打开了相同类型的元素 [英] Error: An a start tag seen but an element of the same type was already open

查看:94
本文介绍了错误:看到一个开始标记但是已经打开了相同类型的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的doctype是 html5 。我正在验证这个HTML:

My doctype is html5. I am validating this HTML:

<a class="article-link-block" href="http://localhost/article/231">

    <img src="http://localhost/images/article-image.jpg">

    <div class="article-info">
        <a class="title" href="http://localhost/article/231">Title of the article</a>
        <a class="category" href="http://localhost/category/5">Category</a>
        <div class="views">24x</div>
        <div class="date">13.3.2013</div>
    </div>

</a>

我收到此错误:

Error: An a start tag seen but an element of the same type was already open.

我希望整个 div 成为一个锚标记( article-link-block ),并在其中包含另一个锚标记到类别,用户等和其他div(上面的代码简化为只有文章和类别链接。)

I want the whole div to be an anchor tag ( article-link-block ) and within it another anchor tags to category, user etc. and other divs (the code above is simplified to only article and category link.)

如何在html验证期间摆脱此错误?

How can I get rid of this error during html validation?

推荐答案

如果你想要这一切都是为了验证您是否需要选择是否需要块级链接或子链接。你不能兼得。来自规范

If you want it all to validate you're going to have to choose whether you want the block level link, or the child links. You can't have both. From the spec:


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

Content model: Transparent, but there must be no interactive content descendant.

互动内容是:


a audio (如果控件属性存在)按钮 详细信息 嵌入 iframe img (如果 usemap 属性存在)输入(如果类型属性未处于隐藏状态) keygen label object (如果 usemap 属性存在) select textarea vid eo (如果控件属性存在)

a audio (if the controls attribute is present) button details embed iframe img (if the usemap attribute is present) input (if the type attribute is not in the Hidden state) keygen label object (if the usemap attribute is present) select textarea video (if the controls attribute is present)

所以你的选择是:


  1. 忽略验证器并保持原样(你没有权利期望所有的浏览器都表现出来在这种情况下以相同的方式)

  2. 完全选择不同的标记结构

  3. 将块级别或子链接替换为普通元素和点击活动

  1. Ignore the validator and keep it as it is (you have no right to expect all browsers to behave in the same way in this case)
  2. Choose a different markup structure altogether
  3. Replace either the block level or child links with normal elements and click events

这篇关于错误:看到一个开始标记但是已经打开了相同类型的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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