A Pen by Fooleap Chen on CodePen.
Created
September 16, 2015 05:00
-
-
Save fooleap/6949a9f325865c6f2279 to your computer and use it in GitHub Desktop.
ZbQPLL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>参考资料</title> | |
</head> | |
<body> | |
那一天,我在街上看到了条狗<a href="https://zh.wikipedia.org/wiki/狗" title="狗 - 维基百科">[1]</a>,后来发现居然是只狼<a href="https://zh.wikipedia.org/wiki/狼" title="狼 - 维基百科">[2]</a>。 | |
<div style="height:400px;"></div> | |
<h2>参考资料</h2> | |
<ol id="refs"></ol> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(){ | |
// 选择非本站链接 | |
$('a[href*="http:"]:not([href*="' + location.hostname + '"]), [href*="https:"]:not([href*="' + location.hostname + '"])').each(function(){ | |
// 去掉所选链接文本的最前、最后字符 | |
var num = $(this).text().substring(1, $(this).text().length-1); | |
// 判断是否为数字 | |
if(parseInt(num)){ | |
var note = 'note-' + num; | |
var ref = 'ref-' + num; | |
var noteTitle = $(this).attr('title'); | |
var noteHref = $(this).attr('href'); | |
$(this).attr({href: '#' + note, id: ref, 'class': 'ref'}).wrap('<sup>'); | |
$('#refs').append('<li class="note"><a href="#'+ ref + '">∧</a> <a href="'+ noteHref + '" title="' + noteTitle + '" id="' + note +'" class="exf-text" target="_blank">' + noteTitle + '</a></li>') | |
} else { | |
// 不是数字保留并加上 target 属性 | |
$(this).attr('target', '_blank'); | |
}; | |
}); | |
var noteLinks = $('a[href^="#note"], a[href^="#ref"]'); | |
noteLinks.click(function(){ | |
// 清除背景颜色 | |
noteLinks.parent().css('background-color', ''); | |
// 高亮目标背景 | |
var href = $(this).attr('href'); | |
$(href).parent().css('background-color', 'rgb(235, 235, 235)'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment