前端之家收集整理的这篇文章主要介绍了
jquery – 如何以编程方式为我的页眉创建锚点?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
function addAnchors(){
//loop through all your headers
$.each($('h1'),function(index,value){
//append the text of your header to a list item in a div,linking to an anchor we will create on the next line
$('#Box-anchors').append('<li><a href="#anchor-'+index+'">'+$(this).html()+'</a></li>');
//add an a tag to the header with a sequential name
$(this).html('<a name="anchor-'+index+'">'+$(this).html()+'</a>');
});
}
原文链接:https://www.f2er.com/jquery/178762.html