前言

本教程基于尚硅谷Web前端教程发布,你们也可以理解为这是一篇尚硅谷教程的笔记,当然这里也有我自己的一些经验总结

什么是语义标签

语义话标签都有它的直观含义,能够方便阅读。如:

1
2
<p>一行语义标签旨一个段落</p>
<span>一行语义话标签文字无特殊含义</span>

如上文,这两行标签都是语义话标签,但语义各不相同
使用语义标签时应该关注它的语义而不只关注它的样式

什么意思?
Screenshot_2024_0208_061013
如图,这里有两个标签<h1><h2>在直观的感受中我们感觉到<h1>是比<h2>大的,但这个不重要,我们可以通过CSS来让<h1>变得比<h2>小,也可以相反<2>变得比<h1>大,所以我们只关注它的语义而不关注它的样式

优势

1)代码结构清晰,方便阅读,有利于团队合作开发。

2)方便其他设备解析(如屏幕阅读器、盲人阅读器、移动设备)以语义的方式来渲染网页。

3)有利于搜索引擎优化(SEO)。

因此我们在写页面结构时,应尽量使用有 语义的HTML 标签

那么有哪些是常见的HTML标签呢

常见的

  • <title>:页面标题,这个不用多说了吧

  • <h1>:分级标题有h1~`h6,其与`配合有利于搜索引擎优化。</p> </li> <li><p><code><ul></code>:<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/ul">无序列表</a></p> </li> <li><p><code><ol></code>:<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/ol">有序列表</a></p> </li> <li><p><code><header></code>:网站眉页,通常包括网站标志、主导航、全站链接以及搜索框。</p> </li> <li><p><code><nav></code>:<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/nav">标记导航</a>仅对文档中重要的链接群使用。</p> </li> <li><p><code><main></code>:页面主要内容,一个页面只能使用一次。如果是web应用,则包围其主要功能。</p> </li> <li><p><code><article></code><a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/article">定义外部的内容</a>,其中的内容独立于文档的其余部分。</p> </li> <li><p><code><section></code>:定义文档中的节(section、区段)。比如章节、页眉、页脚或文档中的其他部分。</p> </li> <li><p><code><aside></code>:<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/aside">定义</a>其所处内容之外的内容。如侧栏、文章的一组链接、广告、友情链接、相关产品列表等。</p> </li> <li><p><code><footer></code>:页脚,只有当父级是body时,才是整个页面的页脚。</p> </li> <li><p><code><small></code>:呈现小号字体效果,指定细则,输入免责声明、注解、署名、版权。</p> </li> <li><p><code><strong></code>:与<code>em</code>一样用于强调文本,但相比它强调的更强一些</p> </li> <li><p><code><em></code>:将其中的文本表示为强调的内容,表现为<em>斜体</em></p> </li> <li><p><code><mark></code>:使用黄色突出显示部分文本。</p> </li> <li><p><code><figure></code>:<a target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/figure">规定</a>独立的流内容(图像、图表、照片、代码等等)(默认有40px左右margin)。</p> </li> </ul> <blockquote> <p>更多<a target="_blank" rel="noopener" href="http://t.csdnimg.cn/etL8F">http://t.csdnimg.cn/etL8F</a></p> </blockquote> <div class="article-footer fs14"> <section id="license"> <div class="header"><span>许可协议</span></div> <div class="body"><p>本文采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">署名-非商业性使用-相同方式共享 4.0 国际</a> 许可协议,转载请注明出处。</p> </div> </section> <section id="share"> <div class="header"><span>分享文章</span></div> <div class="body"> <div class="link"><input class="copy-area" readonly="true" id="copy-link" value="https://linexic.top/2024/02/07/guigu-html-10/" /></div> <div class="social-wrap dis-select"><a class="social share-item wechat" onclick="util.toggle("qrcode-wechat")"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/b32ef3da1162a.svg" /></a><a class="social share-item weibo" target="_blank" rel="external nofollow noopener noreferrer" href="https://service.weibo.com/share/share.php?url=https://linexic.top/2024/02/07/guigu-html-10/&title=【前端10】语义化标签 - LineXic书屋&summary=前言 本教程基于尚硅谷Web前端教程发布,你们也可以理解为这是一篇尚硅谷教程的笔记,当然这里也有我自己的一些经验总结 什么是语义标签语义话标签都有它的直观含义,能够方便阅读。如: 12<p>一行语义标签旨一个段落<..."><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/80c07e4dbb303.svg" /></a><a class="social share-item email" href="mailto:?subject=【前端10】语义化标签 - LineXic书屋&body=https://linexic.top/2024/02/07/guigu-html-10/"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/a1b00e20f425d.svg" /></a><a class="social share-item link" onclick="util.copy("copy-link", "复制成功")"><img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://gcore.jsdelivr.net/gh/cdn-x/placeholder@1.0.12/social/8411ed322ced6.svg" /></a></div> <div class="qrcode" id="qrcode-wechat" style="opacity:0;height:0"> <img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://api.qrserver.com/v1/create-qr-code/?size=256x256&data=https://linexic.top/2024/02/07/guigu-html-10/"/> </div> </div> </section> </div> </article> <div class="related-wrap" id="read-next"><section class="body"><div class="item" id="prev"><div class="note">较新文章</div><a href="/2024/02/17/guigu-html-11/">【前端11】块和行内元素</a></div><div class="item" id="next"><div class="note">较早文章</div><a href="/2024/02/05/guigu-html-9/">【前端9】meta标签</a></div></section></div> <div class="related-wrap md-text" id="comments"> <section class='header cmt-title cap theme'> <p>快来参与讨论吧~(⁠ʘ⁠ᴗ⁠ʘ⁠✿⁠)</p> <img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://www.flyalready.cn/asset/posts/keyboard.png" alt="猫猫" style="margin-left: 10px; height: 50px;"> </section> <section class='body cmt-body twikoo'> <div id="twikoo_container"><svg class="loading" style="vertical-align:middle;fill:currentColor;overflow:hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg></div> </section> </div> <footer class="page-footer footnote"><hr><div class="sitemap"><div class="sitemap-group"><span class="fs15">博客</span><a href="/">近期</a><a href="/categories">分类</a><a href="/tags">标签</a><a href="/archives">归档</a></div><div class="sitemap-group"><span class="fs15">项目</span><a target="_blank" rel="noopener" href="https://gh.linexic.top/">GH加速</a><a target="_blank" rel="noopener" href="https://i.linexic.top/">个人站</a><a target="_blank" rel="noopener" href="https://chat.linexic.top/">ChatAi</a><a target="_blank" rel="noopener" href="https://u.linexic.top/">Umami</a></div><div class="sitemap-group"><span class="fs15">探索</span><a target="_blank" rel="noopener" href="https://travel.moe/go?travel=on">异次元之旅</a><a target="_blank" rel="noopener" href="https://www.foreverblog.cn/">十年之约</a><a target="_blank" rel="noopener" href="https://www.boyouquan.com/planet-shuttle">博友圈</a><a target="_blank" rel="noopener" href="https://blogecho.zeimg.top/">回响</a></div><div class="sitemap-group"><span class="fs15">更多</span><a href="/about">关于我</a><a href="/friends">友链</a><a href="/sitemap.xml">SiteMap</a><a href="/atom.xml">Atom</a></div></div><span class="totalcount">发表了 48 篇文章 · </span><span class="post-count">总计 29.2k 字</span><div class="text"><p>本站由 <a href="/">LineXic</a> 使用 <a target="_blank" rel="noopener" href="https://github.com/xaoxuu/hexo-theme-stellar/tree/1.29.1">Stellar 1.29.1</a> 主题创建。<br>本博客所有文章除特别声明外,均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议,转载请注明出处。</p> <div style="text-align:center"> <a href="https://idc.natriumgroup.com/aff/FCKCZNPT" target="_blank"> <img class="lazy" width="100%" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://idc.natriumgroup.com/upload/long.png" alt="纳云计算"> </a> <img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://img.shields.io/badge/Hexo-Stellar-blue" alt="搭建框架"> <img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://img.shields.io/badge/Vercel-Database-black" alt="托管"> <br/> <img class="lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAAaADAAQAAAABAAAAAQAAAADa6r/EAAAAC0lEQVQIHWNgAAIAAAUAAY27m/MAAAAASUVORK5CYII=" data-src="https://icp.gov.moe/images/ico64.png" width="20" height="20"><a href="https://icp.gov.moe/?keyword=20240181" target="_blank">萌ICP备20240181号</a><br> <p>我们会像繁星一样灿烂的活下去</p> <p>你是自己永远生机勃勃的战友,而不是别人投射在你身上的幽灵</p> <span id="sitetime"></span> <script language=javascript> function siteTime(){ window.setTimeout("siteTime()", 1000); var seconds = 1000; var minutes = seconds * 60; var hours = minutes * 60; var days = hours * 24; var years = days * 365; var today = new Date(); var todayYear = today.getFullYear(); var todayMonth = today.getMonth()+1; var todayDate = today.getDate(); var todayHour = today.getHours(); var todayMinute = today.getMinutes(); var todaySecond = today.getSeconds(); /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳) year - 作为date对象的年份,为4位年份值 month - 0-11之间的整数,做为date对象的月份 day - 1-31之间的整数,做为date对象的天数 hours - 0(午夜24点)-23之间的整数,做为date对象的小时数 minutes - 0-59之间的整数,做为date对象的分钟数 seconds - 0-59之间的整数,做为date对象的秒数 microseconds - 0-999之间的整数,做为date对象的毫秒数 */ var t1 = Date.UTC(2023,09,02,00,00,00); //北京时间2016-12-1 00:00:00 var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond); var diff = t2-t1; var diffYears = Math.floor(diff/years); var diffDays = Math.floor((diff/days)-diffYears*365); var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours); var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes); var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds); document.getElementById("sitetime").innerHTML="匍匐爬行"+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒"; } siteTime(); </script> </div> </div></footer><div class="main-mask" onclick="sidebar.dismiss()"></div></div><aside class="l_right"> <div class="widgets"> <widget class="widget-wrapper toc" id="data-toc" collapse="false"><div class="widget-header dis-select"><span class="name">本文目录</span><a class="cap-action" onclick="sidebar.toggleTOC()" ><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6h11m-11 6h11m-11 6h11M4 6h1v4m-1 0h2m0 8H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg></a></div><div class="widget-body"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E8%AF%AD%E4%B9%89%E6%A0%87%E7%AD%BE"><span class="toc-text">什么是语义标签</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BC%98%E5%8A%BF"><span class="toc-text">优势</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81%E7%9A%84"><span class="toc-text">常见的</span></a></li></ol></div><div class="widget-footer"> <a class="top" onclick="util.scrollTop()"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 12c0-4.714 0-7.071 1.464-8.536C4.93 2 7.286 2 12 2c4.714 0 7.071 0 8.535 1.464C22 4.93 22 7.286 22 12c0 4.714 0 7.071-1.465 8.535C19.072 22 16.714 22 12 22s-7.071 0-8.536-1.465C2 19.072 2 16.714 2 12Z"/><path stroke-linecap="round" stroke-linejoin="round" d="m9 15.5l3-3l3 3m-6-4l3-3l3 3"/></g></svg><span>回到顶部</span></a><a class="buttom" onclick="util.scrollComment()"><svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="currentColor" fill-rule="evenodd" d="M10.46 1.25h3.08c1.603 0 2.86 0 3.864.095c1.023.098 1.861.3 2.6.752a5.75 5.75 0 0 1 1.899 1.899c.452.738.654 1.577.752 2.6c.095 1.004.095 2.261.095 3.865v1.067c0 1.141 0 2.036-.05 2.759c-.05.735-.153 1.347-.388 1.913a5.75 5.75 0 0 1-3.112 3.112c-.805.334-1.721.408-2.977.43a10.81 10.81 0 0 0-.929.036c-.198.022-.275.054-.32.08c-.047.028-.112.078-.224.232c-.121.166-.258.396-.476.764l-.542.916c-.773 1.307-2.69 1.307-3.464 0l-.542-.916a10.605 10.605 0 0 0-.476-.764c-.112-.154-.177-.204-.224-.232c-.045-.026-.122-.058-.32-.08c-.212-.023-.49-.03-.93-.037c-1.255-.021-2.171-.095-2.976-.429A5.75 5.75 0 0 1 1.688 16.2c-.235-.566-.338-1.178-.389-1.913c-.049-.723-.049-1.618-.049-2.76v-1.066c0-1.604 0-2.86.095-3.865c.098-1.023.3-1.862.752-2.6a5.75 5.75 0 0 1 1.899-1.899c.738-.452 1.577-.654 2.6-.752C7.6 1.25 8.857 1.25 10.461 1.25M6.739 2.839c-.914.087-1.495.253-1.959.537A4.25 4.25 0 0 0 3.376 4.78c-.284.464-.45 1.045-.537 1.96c-.088.924-.089 2.11-.089 3.761v1c0 1.175 0 2.019.046 2.685c.045.659.131 1.089.278 1.441a4.25 4.25 0 0 0 2.3 2.3c.515.214 1.173.294 2.429.316h.031c.398.007.747.013 1.037.045c.311.035.616.104.909.274c.29.17.5.395.682.645c.169.232.342.525.538.856l.559.944a.52.52 0 0 0 .882 0l.559-.944c.196-.331.37-.624.538-.856c.182-.25.392-.476.682-.645c.293-.17.598-.24.909-.274c.29-.032.639-.038 1.037-.045h.032c1.255-.022 1.913-.102 2.428-.316a4.25 4.25 0 0 0 2.3-2.3c.147-.352.233-.782.278-1.441c.046-.666.046-1.51.046-2.685v-1c0-1.651 0-2.837-.089-3.762c-.087-.914-.253-1.495-.537-1.959a4.25 4.25 0 0 0-1.403-1.403c-.464-.284-1.045-.45-1.96-.537c-.924-.088-2.11-.089-3.761-.089h-3c-1.651 0-2.837 0-3.762.089" clip-rule="evenodd"/><path fill="currentColor" d="M9 11a1 1 0 1 1-2 0a1 1 0 0 1 2 0m4 0a1 1 0 1 1-2 0a1 1 0 0 1 2 0m4 0a1 1 0 1 1-2 0a1 1 0 0 1 2 0"/></svg><span>参与讨论</span></a></div></widget> </div></aside><div class='float-panel blur'> <button type='button' style='display:none' class='laptop-only rightbar-toggle mobile' onclick='sidebar.rightbar()'> <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6h11m-11 6h11m-11 6h11M4 6h1v4m-1 0h2m0 8H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg> </button> <button type='button' style='display:none' class='mobile-only leftbar-toggle mobile' onclick='sidebar.leftbar()'> <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-width="1.5"><path d="M2 11c0-3.771 0-5.657 1.172-6.828C4.343 3 6.229 3 10 3h4c3.771 0 5.657 0 6.828 1.172C22 5.343 22 7.229 22 11v2c0 3.771 0 5.657-1.172 6.828C19.657 21 17.771 21 14 21h-4c-3.771 0-5.657 0-6.828-1.172C2 18.657 2 16.771 2 13z"/><path id="sep" stroke-linecap="round" d="M5.5 10h6m-5 4h4m4.5 7V3"/></g></svg> </button> </div> </div><div class="scripts"> <script type="text/javascript"> const ctx = { date_suffix: { just: `刚刚`, min: `分钟前`, hour: `小时前`, day: `天前`, }, root : `/`, }; // required plugins (only load if needs) if (`local_search`) { ctx.search = {}; ctx.search.service = `local_search`; if (ctx.search.service == 'local_search') { let service_obj = Object.assign({}, `{"field":"all","path":"/search.json","content":true,"sort":"-date"}`); ctx.search[ctx.search.service] = service_obj; } } const def = { avatar: `https://jsdelivr.linexic.top/gh/cdn-x/placeholder@1.0.12/avatar/round/3442075.svg`, cover: `https://jsdelivr.linexic.top/gh/cdn-x/placeholder@1.0.12/cover/76b86c0226ffd.svg`, }; const deps = { jquery: `https://jsdelivr.linexic.top/npm/jquery@3.7.1/dist/jquery.min.js`, marked: `https://jsdelivr.linexic.top/npm/marked@13.0.1/lib/marked.umd.min.js` } </script> <script type="text/javascript"> const utils = { // 懒加载 css https://github.com/filamentgroup/loadCSS css: (href, before, media, attributes) => { var doc = window.document; var ss = doc.createElement("link"); var ref; if (before) { ref = before; } else { var refs = (doc.body || doc.getElementsByTagName("head")[0]).childNodes; ref = refs[refs.length - 1]; } var sheets = doc.styleSheets; if (attributes) { for (var attributeName in attributes) { if (attributes.hasOwnProperty(attributeName)) { ss.setAttribute(attributeName, attributes[attributeName]); } } } ss.rel = "stylesheet"; ss.href = href; ss.media = "only x"; function ready(cb) { if (doc.body) { return cb(); } setTimeout(function () { ready(cb); }); } ready(function () { ref.parentNode.insertBefore(ss, before ? ref : ref.nextSibling); }); var onloadcssdefined = function (cb) { var resolvedHref = ss.href; var i = sheets.length; while (i--) { if (sheets[i].href === resolvedHref) { return cb(); } } setTimeout(function () { onloadcssdefined(cb); }); }; function loadCB() { if (ss.addEventListener) { ss.removeEventListener("load", loadCB); } ss.media = media || "all"; } if (ss.addEventListener) { ss.addEventListener("load", loadCB); } ss.onloadcssdefined = onloadcssdefined; onloadcssdefined(loadCB); return ss; }, js: (src, opt) => new Promise((resolve, reject) => { var script = document.createElement('script'); if (src.startsWith('/')){ src = ctx.root + src.substring(1); } script.src = src; if (opt) { for (let key of Object.keys(opt)) { script[key] = opt[key] } } else { // 默认异步,如果需要同步,第二个参数传入 {} 即可 script.async = true } script.onerror = reject script.onload = script.onreadystatechange = function() { const loadState = this.readyState if (loadState && loadState !== 'loaded' && loadState !== 'complete') return script.onload = script.onreadystatechange = null resolve() } document.head.appendChild(script) }), jq: (fn) => { if (typeof jQuery === 'undefined') { utils.js(deps.jquery).then(fn) } else { fn() } }, onLoading: (el) => { if (el) { $(el).append('<div class="loading-wrap"><svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" stroke-opacity=".3" d="M12 3C16.9706 3 21 7.02944 21 12C21 16.9706 16.9706 21 12 21C7.02944 21 3 16.9706 3 12C3 7.02944 7.02944 3 12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="1.3s" values="60;0"/></path><path stroke-dasharray="15" stroke-dashoffset="15" d="M12 3C16.9706 3 21 7.02944 21 12"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.3s" values="15;0"/><animateTransform attributeName="transform" dur="1.5s" repeatCount="indefinite" type="rotate" values="0 12 12;360 12 12"/></path></g></svg></div>'); } }, onLoadSuccess: (el) => { if (el) { $(el).find('.loading-wrap').remove(); } }, onLoadFailure: (el) => { if (el) { $(el).find('.loading-wrap svg').remove(); $(el).find('.loading-wrap').append('<svg xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path stroke-dasharray="60" stroke-dashoffset="60" d="M12 3L21 20H3L12 3Z"><animate fill="freeze" attributeName="stroke-dashoffset" dur="0.5s" values="60;0"/></path><path stroke-dasharray="6" stroke-dashoffset="6" d="M12 10V14"><animate fill="freeze" attributeName="stroke-dashoffset" begin="0.6s" dur="0.2s" values="6;0"/></path></g><circle cx="12" cy="17" r="1" fill="currentColor" fill-opacity="0"><animate fill="freeze" attributeName="fill-opacity" begin="0.8s" dur="0.4s" values="0;1"/></circle></svg>'); $(el).find('.loading-wrap').addClass('error'); } }, request: (el, url, callback, onFailure) => { let retryTimes = 3; utils.onLoading(el); function req() { return new Promise((resolve, reject) => { let status = 0; // 0 等待 1 完成 2 超时 let timer = setTimeout(() => { if (status === 0) { status = 2; timer = null; reject('请求超时'); if (retryTimes == 0) { onFailure(); } } }, 5000); fetch(url).then(function(response) { if (status !== 2) { clearTimeout(timer); resolve(response); timer = null; status = 1; } if (response.ok) { return response.json(); } throw new Error('Network response was not ok.'); }).then(function(data) { retryTimes = 0; utils.onLoadSuccess(el); callback(data); }).catch(function(error) { if (retryTimes > 0) { retryTimes -= 1; setTimeout(() => { req(); }, 5000); } else { utils.onLoadFailure(el); onFailure(); } }); }); } req(); }, }; </script> <script> const sidebar = { leftbar: () => { if (l_body) { l_body.toggleAttribute('leftbar'); l_body.removeAttribute('rightbar'); } }, rightbar: () => { if (l_body) { l_body.toggleAttribute('rightbar'); l_body.removeAttribute('leftbar'); } }, dismiss: () => { if (l_body) { l_body.removeAttribute('leftbar'); l_body.removeAttribute('rightbar'); } }, toggleTOC: () => { document.querySelector('#data-toc').classList.toggle('collapse'); } } </script> <script type="text/javascript"> (() => { const tagSwitchers = document.querySelectorAll('.tag-subtree.parent-tag > a > .tag-switcher-wrapper') for (const tagSwitcher of tagSwitchers) { tagSwitcher.addEventListener('click', (e) => { const parent = e.target.closest('.tag-subtree.parent-tag') parent.classList.toggle('expanded') e.preventDefault() }) } // Get active tag from query string, then activate it. const urlParams = new URLSearchParams(window.location.search) const activeTag = urlParams.get('tag') if (activeTag) { let tag = document.querySelector(`.tag-subtree[data-tag="${activeTag}"]`) if (tag) { tag.querySelector('a').classList.add('active') while (tag) { tag.classList.add('expanded') tag = tag.parentElement.closest('.tag-subtree.parent-tag') } } } })() </script> <!-- required --> <script src="/js/main.js?v=1.29.1" defer></script> <script type="text/javascript"> const applyTheme = (theme) => { if (theme === 'auto') { document.documentElement.removeAttribute('data-theme') } else { document.documentElement.setAttribute('data-theme', theme) } applyThemeToGiscus(theme) } const applyThemeToGiscus = (theme) => { theme = theme === 'auto' ? 'preferred_color_scheme' : theme const cmt = document.getElementById('giscus') if (cmt) { // This works before giscus load. cmt.setAttribute('data-theme', theme) } const iframe = document.querySelector('#comments > section.giscus > iframe') if (iframe) { // This works after giscus loaded. const src = iframe.src const newSrc = src.replace(/theme=[\w]+/, `theme=${theme}`) iframe.src = newSrc } } const switchTheme = () => { // light -> dark -> auto -> light -> ... const currentTheme = document.documentElement.getAttribute('data-theme') let newTheme; switch (currentTheme) { case 'light': newTheme = 'dark' break case 'dark': newTheme = 'auto' break default: newTheme = 'light' } applyTheme(newTheme) window.localStorage.setItem('Stellar.theme', newTheme) const messages = { light: `切换到浅色模式`, dark: `切换到深色模式`, auto: `切换到跟随系统配色`, } hud?.toast?.(messages[newTheme]) } (() => { // Apply user's preferred theme, if any. const theme = window.localStorage.getItem('Stellar.theme') if (theme !== null) { applyTheme(theme) } })() </script> <!-- optional --> <script type="module"> const el = document.getElementById('twikoo_container'); util.viewportLazyload(el, load_twikoo, false); function load_twikoo() { if (!el) return; utils.js('https://jsdelivr.linexic.top/npm/twikoo@1.6.8/dist/twikoo.all.min.js', {defer: true}).then(function () { const path = el.getAttribute('comment_id') ?? decodeURI(window.location.pathname); twikoo.init(Object.assign({"js":"https://jsdelivr.linexic.top/npm/twikoo@1.6.8/dist/twikoo.all.min.js","envId":"https://twikoo.linexic.top/"}, { el: '#twikoo_container', path: path, })); }); } </script> <script defer> window.addEventListener('DOMContentLoaded', (event) => { ctx.services = Object.assign({}, JSON.parse(`{"mdrender":{"js":"/js/services/mdrender.js"},"siteinfo":{"js":"/js/services/siteinfo.js","api":"https://info.linexic.top/api/v1/?url={href}"},"ghinfo":{"js":"/js/services/ghinfo.js"},"sites":{"js":"/js/services/sites.js"},"friends":{"js":"/js/services/friends.js"},"timeline":{"js":"/js/services/timeline.js"},"fcircle":{"js":"/js/services/fcircle.js"},"weibo":{"js":"/js/services/weibo.js"},"memos":{"js":"/js/services/memos.js"}}`)); for (let id of Object.keys(ctx.services)) { const js = ctx.services[id].js; if (id == 'siteinfo') { ctx.cardlinks = document.querySelectorAll('a.link-card[cardlink]'); if (ctx.cardlinks?.length > 0) { utils.js(js, { defer: true }).then(function () { setCardLink(ctx.cardlinks); }); } } else { const els = document.getElementsByClassName(`ds-${id}`); if (els?.length > 0) { utils.jq(() => { if (id == 'timeline' || 'memos' || 'marked') { utils.js(deps.marked).then(function () { utils.js(js, { defer: true }); }); } else { utils.js(js, { defer: true }); } }); } } } }); </script> <script> window.addEventListener('DOMContentLoaded', (event) => { ctx.search = { path: `/search.json`, } utils.js('/js/search/local-search.js', { defer: true }); }); </script><script> window.FPConfig = { delay: 0, ignoreKeywords: [], maxRPS: 5, hoverDelay: 25 }; </script> <script defer src="https://jsdelivr.linexic.top/npm/flying-pages@2/flying-pages.min.js"></script><script defer src="https://jsdelivr.linexic.top/npm/vanilla-lazyload@19.1.3/dist/lazyload.min.js"></script> <script> // https://www.npmjs.com/package/vanilla-lazyload // Set the options globally // to make LazyLoad self-initialize window.lazyLoadOptions = { elements_selector: ".lazy", }; // Listen to the initialization event // and get the instance of LazyLoad window.addEventListener( "LazyLoad::Initialized", function (event) { window.lazyLoadInstance = event.detail.instance; }, false ); document.addEventListener('DOMContentLoaded', function () { window.lazyLoadInstance?.update(); }); </script><script> ctx.fancybox = { selector: `.swiper-slide img, .vcontent img:not(.vemoji), .tag-plugin.image img`, css: `https://jsdelivr.linexic.top/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.css`, js: `https://jsdelivr.linexic.top/npm/@fancyapps/ui@5.0/dist/fancybox/fancybox.umd.js` }; var selector = '[data-fancybox]:not(.error)'; if (ctx.fancybox.selector) { selector += `, ${ctx.fancybox.selector}` } var needFancybox = document.querySelectorAll(selector).length !== 0; if (!needFancybox) { const els = document.getElementsByClassName('ds-memos'); if (els != undefined && els.length > 0) { needFancybox = true; } } if (needFancybox) { utils.css(ctx.fancybox.css); utils.js(ctx.fancybox.js, { defer: true }).then(function () { Fancybox.bind(selector, { hideScrollbar: false, Thumbs: { autoStart: false, }, caption: (fancybox, slide) => { return slide.triggerEl.alt || slide.triggerEl.dataset.caption || null } }); }) } </script> <script> window.addEventListener('DOMContentLoaded', (event) => { const swiper_api = document.getElementById('swiper-api'); if (swiper_api != undefined) { utils.css(`https://unpkg.com/swiper@10.3.1/swiper-bundle.min.css`); utils.js(`https://unpkg.com/swiper@10.3.1/swiper-bundle.min.js`, { defer: true }).then(function () { const effect = swiper_api.getAttribute('effect') || ''; var swiper = new Swiper('.swiper#swiper-api', { slidesPerView: 'auto', spaceBetween: 8, centeredSlides: true, effect: effect, rewind: true, pagination: { el: '.swiper-pagination', clickable: true, }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }); }) } }); </script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({ tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ], processEscapes: true } }); MathJax.Hub.Config({ tex2jax: { skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'] } }); MathJax.Hub.Queue(function() { var all = MathJax.Hub.getAllJax(), i; for(i=0; i < all.length; i += 1) { all[i].SourceElement().parentNode.className += ' has-jax'; } }); </script> <script> document.addEventListener('DOMContentLoaded', function () { window.codeElements = document.querySelectorAll('.code'); if (window.codeElements.length > 0) { ctx.copycode = { default_text: `Copy`, success_text: `Copied`, toast: `复制成功`, }; utils.js('/js/plugins/copycode.js'); } }); </script> <!-- inject --> </div></body></html>