您可以使用 relative 属性用任意标签标记超链接吗?

Can you tag hyperlinks with arbitrary tags using the relative attribute?

以下语法似乎在 HTML 中有效:

 <a rel="nofollow" href="http://www.functravel.com/">Cheap Flights</a>

现在,假设我想在 "nofollow" 的位置插入一个任意单词,这有效吗?例如,假设有三种超链接:红色、绿色和蓝色。然后我可以将它们用作标签,如下所示:

<a rel="green" href="http://www.functravel.com/">Cheap Flights</a> 

如果允许上述情况,我可以更进一步,定义一个具有两个或多个相关属性的超链接,如下所示:

 <a rel="nofollow red" href="http://www.functravel.com/">Cheap Flights</a> 

我只是对理论上的可能性感兴趣。

rel 属性指定当前文档和链接文档之间的关系。仅当存在 href 属性时才使用它。

rel 属性的一些接受值是备用、作者、书签、外部等。Visit the link to know more rel values

此外,如果您使用自定义值,如蓝色、绿色和其他任何值,您可以通过 jquery 访问该值,但如果您在 w3 Validator 上验证页面,它将提供你错了。

例如:

<a id='_toBlue' rel='blue' href='blue.php'>blue</a>
<a id='_toGreen' rel='green' href='green.php'>green</a>

并且使用 JQuery 您可以出于某种目的获得相对值

var relBlue = "#!"+$("#_toBlue").attr('rel'); //gives desired result=>"blue"
var relGreen = "#!"+$("#_toGreen").attr('rel'); //gives desired result=>"green"

现在,当您在 W3 验证程序中验证此 HTML 时,您会收到以下错误

Bad value #blue for attribute rel on element a: Keyword #blue is not registered.

Bad value #green for attribute rel on element a: Keyword #green is not registered.

因此,如果您对它没意见,就可以使用它,但强烈不推荐

HTML 规范定义了 allowed values for the rel attribute

由于存在一组允许的值,因此(隐含地)不允许偏离该列表(如果您尝试 validation 将抛出错误)。

class 属性允许您向任何元素添加任意标签。 data-* 属性还允许您向元素添加自定义信息。请改用其中之一。