优化获取网页标题

pull/1/head
东子 2018-12-13 22:15:03 +08:00
parent 5503ba045a
commit 97733de2d0
1 changed files with 4 additions and 5 deletions

View File

@ -32,11 +32,10 @@
<script>hljs.initHighlightingOnLoad();</script> <script>hljs.initHighlightingOnLoad();</script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
//获取第一个H1作为标题 // 设置网页标题为第一个H标签的内容
var h1 = $("h1").text(); var hText = $(":header:first").text(); // 取第一个标题Hx元素
//如果获取到了H1 if(hText.length > 0) {
if(h1) { $('title').text(hText); // 设置文档标题
$("title").text(h1 + " - MDtoHTML");
} }
}); });
</script> </script>