From a8d08cadbc18b811a949dd5c91d5ec636710233c Mon Sep 17 00:00:00 2001 From: zhanglei Date: Sat, 9 Oct 2021 13:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcontent=E5=86=85a=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=B2=A1=E6=9C=89href=E5=B1=9E=E6=80=A7=E6=97=B6?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/js/post.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/js/post.js b/source/js/post.js index 0718449..a02750d 100644 --- a/source/js/post.js +++ b/source/js/post.js @@ -369,7 +369,8 @@ $(function () { // 初始化处理,在新标签中打开页面 linkOnBlackPage && $("#content a").filter(function () { - let isLinkToCurrentPage = $(this).attr("href").startsWith("#"); + let titleId = $(this).attr("href"); + let isLinkToCurrentPage = titleId && titleId.startsWith("#"); // 给每个链接到当前页面的链接一个点击事件,通过动画滚动到目标位置 isLinkToCurrentPage && $(this).on('click', function (event) { let titleId = $(this).attr("href"); @@ -409,4 +410,4 @@ $(function () { readProgress(); // 9、为文章中每一个标题都添加一个点击事件,方便锚点分享 addAnchorPoint("article"); -}); \ No newline at end of file +});