Visual Studio不喜欢页面上的锚标记:

  

验证(XHTML 1.0 Transitional):   考虑属性“名称”   过时。一个较新的结构是   推荐使用。

我正在以这种方式使用 name 属性…

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.w3.org/MarkUp/SCHEMA/xhtml11.xsd" xml:lang="en">
    ...
    <body>
        ...
        <p>On this page&hellip;</p>
        <ul>
            <li><a href="#one">Section One</a></li>
            ...
        </ul>
        ...
        <h2><a name="one">Section One</a></h2>
        ...
    </body>
</html>

真的有更现代的方式吗?或者Visual Studio充满了垃圾?

有帮助吗?

解决方案

您应该使用 id 属性。以相同的方式工作,你不需要人工的&lt; a name = ...&gt; ,但只需

<h2 id="one">Section One</h2>

其他提示

XHTML 1.0 中不推荐使用

名称属性 - 您可以在同一个属性中使用id属性但是,请参阅片段标识符 XHTML规范的.w3.org / TR / xhtml1 /#guidelines“rel =”noreferrer“> HTML兼容性指南。

所以你可以简单地使用

<h2><a id="one">Section One</a></h2>

但请注意,1.0规范建议使用以下内容安全地播放它:

<h2><a name="one" id="one">Section One</a></h2>

但是,您的片段使用 XHTML 1.1 ,其中name属性已从 a 地图中完全删除 elements - 所以你只能使用id。

我认为现代方法是使用 id 属性,该属性将被评估为锚点。例如,如果您更改了

<h2><a name="one">Section One</a></h2>

<h2><a id="one">Section One</a></h2>

您仍然可以将其作为 page.html#one 来解决。

您还可以链接节标题:

目录

<P>
    <A href="#section1">Introduction</A><BR>
    <A href="#section2">Some background</A><BR>
    <A href="#section2.1">On a more personal note</A><BR>
    ...the rest of the table of contents...
    ...the document body...

    <H2 id="section1">Introduction</H2>
    ...section 1...

    <H2 id="section2">Some background</H2>
    ...section 2...

    <H3 id="section2.1">On a more personal note</H3>
    ...section 2.1...

[...]
</P>

资料来源: http://www.w3.org/TR /REC-html40/struct/links.html

我认为正确的做法是&lt; a id =&quot; one&quot;&gt;

是的它已经过时了。你应该用“id”替换属性。

引用w3schools页面:

  

&quot; id属性替换名称Attribute   HTML 4.01为元素a,applet,frame,iframe,img和map定义了name属性。在XHTML中,不推荐使用name属性。请改用id。&quot;

http://www.w3schools.com/Xhtml/xhtml_syntax.asp

name = attributes用于标记表单中的元素,并且只能用于&lt; form&gt;元素(输入,文本区域,选择等)。对于其他一切,使用ID =。究竟为什么W3C人员认为需要两种不同的命名元素(使用不同的允许字符集)的方法并不为人所知。

但请点击 http://www.w3。 org / TR / html4 / struct / links.html#h-12.2.3 我读到这个:“一些较旧的用户代理不支持使用id属性创建的锚点。”所以?

在您使用的(X)HTML标准不再支持&lt; a name =&quot; ...&quot;&gt;&lt; / a&gt; 之前 - 而不仅仅是弃用 - 在链接到同一页面的一部分的锚点上使用 name id 可能是最安全的。来自 W3C的XHTML 1规范

  

在XML中,URI引用以片段结尾的 RFC2396   &quot;#foo&quot; 形式的标识符不引用属性 name =&quot; foo&quot; ;相反,   它们引用具有定义为ID类型的属性的元素,例如HTML中的 id 属性   4.许多现有的HTML客户端不支持以这种方式使用ID类型属性,因此完全相同   可以为这两个属性提供值,以确保最大向前和向后   兼容性(例如,&lt; a id =&quot; foo&quot; name =&quot; foo&quot;&gt; ...&lt; / a&gt;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top