0

I have a big problem with validation HTML 4.01

<li class="exampleclass">
    <noscript>
        <a href="http://www.skni.pl/index.html">  
    </noscript>

    <span id="showLoginboxButton" style="cursor: pointer;">Login</span>

    <noscript></a></noscript>

</li>

How can I fix it? I get such error

end tag for element "A" which is not open

…nboxButton" style="cursor: pointer;">Login

The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

If this error occurred in a script section of your document, you should probably read this FAQ entry.

4

2 回答 2

4

注意你的代码是如何组织的:

<li class="exampleclass">
    <noscript>
        <a href="http://www.skni.pl/index.html">
    </noscript>
    <span id="showLoginboxButton" style="cursor: pointer;">Login</span>
    <noscript>
        </a>
    </noscript>
</li>

<noscript>在关闭<a>.

您不能在 HTML(或 XML)中对标签进行这种交错:每个标签都必须按照打开的顺序关闭。如果标签在另一个元素内打开,那么它必须在外部元素关闭之前关闭。如果不遵守此规则,则会发生验证错误。


为了实现您想要的,您可以执行以下操作:

<li class="exampleclass">
    <span id="showLoginboxButton" style="cursor: pointer; display: none">Login</span>
    <script type="text/javascript">
        document.getElementById('showLoginboxButton').style.display = 'inline';
    </script>
    <noscript>
        <a href="http://www.skni.pl/index.html">Login</a>
    </noscript>
</li>

基本上#showLoginboxButton,只有在启用 JavaScript 时才隐藏并显示它。

当然,像往常一样,尽量避免内联样式和脚本标签。我在那里添加它们只是为了举例,你最终应该在更合适的地方使用 CSS 类和 JavaScript 代码。

于 2013-09-17T14:53:22.400 回答
0

@acdcjunior 很好地解释了 HTML 语法和有效性方面发生的情况。在实践方面,最好的方法是避免使用该noscript元素(如 HTML5 草案中所建议的那样)并应用不显眼的 JavaScript 原则。在这种情况下,你可以写

<li class="exampleclass">
    <a href="http://www.skni.pl/index.html" id="showLoginboxButton">Login</a>
</li>

其余的用 CSS 和 JavaScript 完成。您的 JavaScript 将为元素分配一个onclick处理程序,a以便它执行脚本必须执行的操作并最终返回false或以其他方式中止正常的链接处理(如果需要 - 我真的看不出没有服务器端操作如何有意义地进行登录.

或者它应该是一个button. 登录操作确实需要操作按钮而不是链接。

于 2013-09-17T16:27:08.727 回答