繁体   English   中英

如何始终显示锚标记的alt属性

[英]How to always display the alt attribute of an anchor tag

如何始终在HTML中显示锚标记的alt属性?

在这种情况下,我有多个重复的网格,并且想确定日期。
所以我想一直显示标题,如何实现呢?

<a href="#" title="created at 12 october">see details</a>
<a href="#" title="created at 13 october">see details</a>
<a href="#" title="created at 14 october">see details</a>

这是一个演示: https : //jsfiddle.net/wub5y96d/1/

您可以使用content: attr(attribute);输出元素属性的content: attr(attribute); 在伪元素::after::before ,如下所示:

a[title]::after {
  content: ' ('attr(title)')';
}

演示版

试试这个简单的循环

$('a').each(function(){
 var text = $(this).text();
 var title = $(this).attr('title');
 $(this).text(text+'-'+title);
});

人们为什么继续使用Fiddle。 当代码片段可以正常工作时.. :)

您可以直接在SO内部运行它们,这有多酷。 哦,也许只是我..

 a::after { position: absolute; top: 16px; left: 0px; width: 200px; color: silver; content: attr(data-created); font-size: smaller; } a { position:relative; display:inline-block; height: 30px; } 
 <div> <a href="#" data-created="created at 12 october">see details</a> </div> <div> <a href="#" data-created="created at 15 october">see details</a> </div> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM