自定义Joomla页面标题:利用语言覆盖机制实现动态标题

访客 数码 7.1K

自定义Joomla页面标题:利用语言覆盖机制实现动态标题-第1张图片-佛山资讯网

本文详细介绍了如何在Joomla 3.9及更高版本中,利用其强大的语言覆盖(Language Override)机制,结合自定义PHP代码,实现动态生成和设置页面``标签。教程将涵盖从定义语言常量、通过`JText::_`获取本地化文本,到正确使用`JDocument::setTitle()`方法设置页面标题的完整流程,并提供实用代码示例和关键注意事项,帮助开发者创建更具SEO友好性和用户体验的动态标题。</p><h2>Joomla语言覆盖机制简介</h2><p>Joomla的语言覆盖(Language Override)功能是一个强大的工具,允许网站管理员自定义Joomla核心、组件或模块中使用的任何文本字符串,而无需修改原始文件。这对于网站的国际化、本地化以及个性化内容展示至关重要。通过在后台创建一个新的语言常量及其对应的文本,我们可以在前端通过JText::_('YOUR_LANGUAGE_CONSTANT')函数获取到这个自定义文本。</p><h2>挑战:动态设置页面标题</h2><p>在Joomla中,页面标题(即HTML <title> 标签)通常由菜单项、文章标题或特定组件的元数据决定。然而,在某些复杂的应用场景中,我们可能需要根据页面内容、用户选择或其他动态变量来生成完全自定义且动态变化的页面标题。例如,一个旅游网站可能需要根据用户访问的国家显示“便宜的[国家名]度假”这样的标题。</p><p>最初,开发者可能会尝试将动态文本替换到文章内容中,但这并不能直接影响页面的<title>标签。核心问题在于,文章内容和页面标题是两个不同的概念,需要不同的API来处理。</p><h3>错误的尝试与分析</h3><p>在尝试将动态文本应用于页面标题时,常见的误区是将处理文章内容替换的逻辑直接套用到页面标题上。例如,以下代码片段展示了将占位符替换到文章内容中的正确方法:</p><pre class="brush:php;toolbar:false">// 假设 $var['country'] 包含国家信息,例如 'peru' $placeholder_country = JText::_('COM_ACME_PLACEHOLDER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country']))); // 如果语言常量不存在或为空,则设置为空字符串 if($placeholder_country === 'COM_ACME_PLACEER_COUNTRY_'.strtoupper(str_replace('-','_',$var['country'])) || !$placeholder_country) { $placeholder_country = ''; } // 将占位符替换到文章文本中 $article->text = JString::str_ireplace("{%placeholder_country%}", $placeholder_country, $article->text);</pre><p>这段代码能够成功地将 {%placeholder_country%} 替换为通过语言覆盖定义的文本,并显示在文章内容中。</p><p>然而,当尝试将类似逻辑应用于页面标题时,可能会遇到问题:</p><pre class="brush:php;toolbar:false">// 尝试获取语言覆盖文本 $placeholder_nicktitle = JText::_('TITLENICK_'.strtoupper(str_replace('-','_',$var['country']))); if($placeholder_nicktitle === 'TITLENICK_'.strtoupper(str_replace('-','_',$var['country'])) || !$placeholder_nicktitle) { $placeholder_nicktitle = ''; } // 错误地尝试设置标题,这将导致500错误或无效操作 // $document->setTitle = JString::str_ireplace("{%placeholder_nicktitle%}", $placeholder_nicktitle, $article->text); // 或 // $document =& JFactory::getDocument(); // $document->setTitle("JString::str_ireplace(". {%placeholder_nicktitle%}", $placeholder_nicktitle, $article->text);");</pre><p>上述尝试失败的原因有两点:</p><ol><li>$document->setTitle 并不是一个可赋值的属性,而是一个用于设置页面标题的方法。</li><li>setTitle() 方法期望接收一个字符串作为参数,而不是一个函数调用或复杂的表达式。</li></ol><h2>正确实现动态页面标题</h2><p>要正确地利用Joomla语言覆盖机制设置动态页面标题,我们需要明确以下步骤:</p><h3>步骤一:定义语言常量</h3><p>首先,在Joomla后台创建语言覆盖。</p><ol><li>进入Joomla后台,导航至 <strong>扩展 -> 语言 -> 覆盖</strong>。</li><li>点击 <strong>新建</strong>。</li><li>在 <strong>语言常量</strong> 字段中输入您自定义的常量,例如 TITLENICK_PERU。</li><li>在 <strong>文本</strong> 字段中输入该常量对应的页面标题,例如 便宜的秘鲁假期。</li><li>保存。</li></ol><p>重复此过程,为所有需要动态标题的国家或变量定义相应的语言常量。</p><h3>步骤二:在PHP代码中获取动态标题文本</h3><p>接下来,在您的自定义PHP代码中,使用 JText::_ 函数根据当前上下文(例如 $var['country'])获取对应的语言覆盖文本。</p><pre class="brush:php;toolbar:false">// 获取Joomla文档对象 $document = JFactory::getDocument(); // 假设 $var['country'] 已经获取到当前国家信息,例如 'peru' $country_code = strtoupper(str_replace('-','_',$var['country'])); // 转换为大写并替换连字符为下划线,例如 'PERU' // 构造语言常量名,例如 'TITLENICK_PERU' $language_constant = 'TITLENICK_' . $country_code; // 通过 JText::_ 获取语言覆盖中定义的文本 $dynamic_title = JText::_($language_constant); // 检查是否成功获取到文本,如果未找到覆盖或文本为空,则使用默认值或空字符串 if ($dynamic_title === $language_constant || empty($dynamic_title)) { // 如果没有找到对应的语言覆盖,可以设置一个默认标题或者根据需要处理 $dynamic_title = '默认页面标题'; // 例如:'全球度假胜地' }</pre><h3>步骤三:设置页面标题</h3><p>获取到动态标题文本后,使用 JDocument::setTitle() 方法将其设置为当前页面的标题。</p><pre class="brush:php;toolbar:false">// ... (接续步骤二的代码) // 使用获取到的动态标题设置页面标题 $document->setTitle($dynamic_title);</pre><h3>完整示例代码</h3><p>将以上步骤整合,形成一个完整的代码片段:</p><pre class="brush:php;toolbar:false"><?php defined('_JEXEC') or die; // 确保在Joomla环境中运行 // 获取Joomla文档对象 $document = JFactory::getDocument(); // 假设 $var 数组已包含 'country' 键,例如 $var['country'] = 'peru'; // 请根据您的实际数据源调整 $var 的获取方式 $var = array('country' => 'peru'); // 示例数据 // 1. 构造语言常量名 $country_code = strtoupper(str_replace('-','_',$var['country'])); $language_constant = 'TITLENICK_' . $country_code; // 例如 'TITLENICK_PERU' // 2. 通过 JText::_ 获取语言覆盖中定义的文本 $dynamic_title = JText::_($language_constant); // 3. 验证获取结果,如果语言常量不存在或文本为空,则提供备用标题 if ($dynamic_title === $language_constant || empty($dynamic_title)) { // 备用方案:可以设置一个通用标题,或者从其他地方获取默认值 $dynamic_title = '探索世界各地假期'; // 默认标题 } // 4. 使用 JDocument::setTitle() 方法设置页面标题 $document->setTitle($dynamic_title); // 此外,如果还需要在文章内容中替换文本,可以继续使用 JString::str_ireplace // 假设 $article->text 已经包含了文章内容 // $article->text = JString::str_ireplace("{%placeholder_nicktitle%}", $dynamic_title, $article->text); ?></pre><h3>注意事项</h3><ul><li><strong>代码执行位置:</strong> 确保这段PHP代码在Joomla页面渲染的早期阶段执行,例如在自定义组件的视图文件、模块的helper文件或插件的onBeforeCompileHead事件中。过晚执行可能导致标题无法被正确设置。</li><li><strong>调试:</strong> 在开发过程中,可以使用 var_dump($dynamic_title); 或 JFactory::getApplication()->enqueueMessage($dynamic_title, 'message'); 来检查 $dynamic_title 的值是否符合预期。</li><li><strong>语言常量命名规范:</strong> 建议使用大写字母和下划线来命名语言常量,以保持一致性并避免冲突。</li><li><strong>默认标题:</strong> 务必处理语言常量未找到或为空的情况,提供一个合理的默认标题,以防止页面标题为空或显示不友好的常量名。</li><li><strong>JString::str_ireplace vs str_ireplace:</strong> Joomla的 JString::str_ireplace 是PHP内置 str_ireplace 函数的一个包装,功能基本相同,但在某些Joomla旧版本或特定编码环境下可能提供额外的兼容性。通常情况下,可以直接使用PHP原生的 str_ireplace。</li></ul><h2>总结</h2><p>通过以上步骤,我们可以有效地利用Joomla的语言覆盖机制和 JDocument::setTitle() 方法,实现灵活且强大的动态页面标题设置。这种方法不仅能够提升网站的SEO表现,还能根据用户上下文提供更加个性化和精确的页面描述,从而优化用户体验。关键在于理解Joomla不同API的职责,将语言文本的获取与页面标题的设置清晰地分离,并确保代码在正确的生命周期阶段执行。</p> </p> <p class="laiyuan"> 本文转载于:互联网 如有侵犯,请联系zhengruancom@outlook.com删除。<br/>免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。 </p> <div class="topic-content"> </div> <p class="tag-wrap mt mb"> <i class="iconfont-air icon-tag"></i>标签: <span class="padding"><a class="tags br" href="https://www.fsgp.cn/tags/bthsu/" title="标题">标题</a></span> <span class="padding"><a class="tags br" href="https://www.fsgp.cn/tags/yyfgp/" title="语言">语言</a></span> <span class="padding"><a class="tags br" href="https://www.fsgp.cn/tags/ym7qr/" title="页面">页面</a></span> </p> <div class="art-copyright br mb"> <div><strong class="addr">本文地址:</strong> <a href="https://www.fsgp.cn/p/sm/84295.html" target="_blank">https://www.fsgp.cn/p/sm/84295.html</a></div> <div><span class="copyright">版权声明:</span>除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。</div> </div> <div class="social-widget mt clearfix h-0"> <!--打赏[可三码切换]--> <!--点赞--> <!--分享--> </div> </div> </article> <!-- 广告位AD5 --> <div class="prev-next sb br mb clearfix"> <p class="post-prev fl ellipsis"> <span class="prev">上一篇</span><strong><a href="https://www.fsgp.cn/p/sm/84233.html">漫画台App帮助反馈查看指南</a></strong> </p> <p class="post-next fr ellipsis"> <span class="next">下一篇</span><strong><a href="https://www.fsgp.cn/p/sm/84360.html">优化重复条件判断与操作:封装方法提升代码可读性与复用性 </a></strong> </p> </div> <!--相关文章--> <div class="related-art sb br mb"> <p class="c-title"><span class="name">相关文章</span></p> <ul class="ul clearfix"> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93569.html" title="Golang编写高性能运维任务调度程序"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/theme/suiranx_air/image/random_img/9.jpg" alt="Golang编写高性能运维任务调度程序" title="Golang编写高性能运维任务调度程序"> </span> <p class="titile">Golang编写高性能运维任务调度程序</p> </a> </li> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93566.html" title="如何重置洋葱浏览器的所有设置?将洋葱浏览器恢复到初始默认状态的方法"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/theme/suiranx_air/image/random_img/4.jpg" alt="如何重置洋葱浏览器的所有设置?将洋葱浏览器恢复到初始默认状态的方法" title="如何重置洋葱浏览器的所有设置?将洋葱浏览器恢复到初始默认状态的方法"> </span> <p class="titile">如何重置洋葱浏览器的所有设置?将洋葱浏览器恢复到初始默认状态的方法</p> </a> </li> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93540.html" title="夸克浏览器无法保存登录密码怎么办 夸克浏览器密码管理设置教程"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/theme/suiranx_air/image/random_img/6.jpg" alt="夸克浏览器无法保存登录密码怎么办 夸克浏览器密码管理设置教程" title="夸克浏览器无法保存登录密码怎么办 夸克浏览器密码管理设置教程"> </span> <p class="titile">夸克浏览器无法保存登录密码怎么办 夸克浏览器密码管理设置教程</p> </a> </li> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93538.html" title="视频号私信回复频繁怎么办?如何避免视频号私信回复频繁?"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/cache/thumbs/80eb8601bb3ea4a6a734afeefc3bee58-320-200-1.jpeg" alt="视频号私信回复频繁怎么办?如何避免视频号私信回复频繁?" title="视频号私信回复频繁怎么办?如何避免视频号私信回复频繁?"> </span> <p class="titile">视频号私信回复频繁怎么办?如何避免视频号私信回复频繁?</p> </a> </li> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93539.html" title="我的世界网页版永久免费入口 我的世界长期有效入口"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/theme/suiranx_air/image/random_img/4.jpg" alt="我的世界网页版永久免费入口 我的世界长期有效入口" title="我的世界网页版永久免费入口 我的世界长期有效入口"> </span> <p class="titile">我的世界网页版永久免费入口 我的世界长期有效入口</p> </a> </li> <li class="related-item mt fl"> <a href="https://www.fsgp.cn/p/sm/93537.html" title="淘宝怎么投放小红书渠道?投放小红书有用吗?"> <span class="span br"> <img class="img br img-cover" src="https://www.fsgp.cn/zb_users/cache/thumbs/c920f158eebb69185bd962a81d5df91f-320-200-1.jpeg" alt="淘宝怎么投放小红书渠道?投放小红书有用吗?" title="淘宝怎么投放小红书渠道?投放小红书有用吗?"> </span> <p class="titile">淘宝怎么投放小红书渠道?投放小红书有用吗?</p> </a> </li> </ul> </div> <div id="comment" class="post-comment clearfix sb br mt"> <p id="comments-title" class="c-title mb bn"><span>发布评论</span> <span class="comment-num"> (<span class="emphasize">0</span>条评论) </span></p> <div class="compost"> <form id="frmSumbit" target="_self" method="post" action="https://www.fsgp.cn/zb_system/cmd.php?act=cmt&postid=84295&key=a60d81cf0eee4f41c6efcd6e5e0943ce"> <input type="hidden" name="inpId" id="inpId" value="84295"/> <input type="hidden" name="inpRevID" id="inpRevID" value="0"/> <div class="com-name"> <a rel="nofollow" id="cancel-reply" href="#comments" style="display:none;">取消回复</a> </div> <div class="com-info"> <ul> <li> <span class="hide" for="author"></span> <input class="ipt" type="text" name="inpName" id="inpName" value="" tabindex="2" placeholder="昵称(必填)"> </li> <li> <span class="hide" for="author"></span> <input class="ipt" type="text" name="inpEmail" id="inpEmail" value="" tabindex="3" placeholder="邮箱"> </li> <li> <span class="hide" for="author"></span> <input class="ipt" type="text" name="inpHomePage" id="inpHomePage" value="" tabindex="4" placeholder="网址"> </li> </ul> </div> <div class="com-box"> <textarea placeholder="来都来了,说点什么吧..." class="textarea" name="txaArticle" id="txaArticle" cols="5" rows="5" tabindex="1"></textarea> </div> <div class="com-info"><button class="com-submit br brightness" name="sumbit" type="submit" tabindex="5" onclick="return zbp.comment.post()">发布评论</button></div> </form> </div> <div class="comment-list mt"> <p class="no-comment"><i class="iconfont-air icon-sofa"></i>还木有评论哦,快来抢沙发吧~</p> <label id="AjaxCommentBegin"></label> <div class="pagebar mb mt"> <div class="nav-links" > </div> </div> <label id="AjaxCommentEnd"></label> </div> </div> <script> $("#on-new-reward").on("click", function() { $("body").append("<div id='reward-mask'></div>"); $("#new-reward").show(); }); $("#close").on("click", function() { $("#new-reward").hide(); $("#reward-mask").remove(); }); $(".payment-way").bind("click", function() { $(".qrcode-img").hide(); $(".qrCode_" + $(".payment-way").find("input[name=reward-way]:checked").val()).show(); }); </script> </div> <aside id="sidebar" class="hidden-sm-md-lg fr"> <div class="theiaStickySidebar"> <section id="aside_random" class="widget widget_aside_random sb br mb"> <p class="c-title mb"><span class="name">随机图文</span></p> <ul class="widget-content aside_random"><li class="list clearfix"><a href="https://www.fsgp.cn/p/qkl/212.html" title="区块链开发:重构数字世界的秩序与边界"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/bbb7d31132624f3a81b5cb7e8015222a-120-90-1.jpeg" alt="区块链开发:重构数字世界的秩序与边界" class="img-cover br random-img"></span><div class="random-text"> <p class="title">区块链开发:重构数字世界的秩序与边界</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-20 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/yl/283.html" title="徐锦江:银幕上的硬汉与艺术家的多面人生"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/dee55c4ff87b12b8bad005d4ab6bd1cb-120-90-1.png" alt="徐锦江:银幕上的硬汉与艺术家的多面人生" class="img-cover br random-img"></span><div class="random-text"> <p class="title">徐锦江:银幕上的硬汉与艺术家的多面人生</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-21 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/yl/352.html" title="田蕊妮:才华与美貌并重的影视女神"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/3175ce5394320e67b5c1a62dd34cb804-120-90-1.png" alt="田蕊妮:才华与美貌并重的影视女神" class="img-cover br random-img"></span><div class="random-text"> <p class="title">田蕊妮:才华与美貌并重的影视女神</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-21 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li></ul> </section> <section id="aside_hot_comment" class="widget widget_aside_hot_comment sb br mb"> <p class="c-title mb"><span class="name">热评文章</span></p> <ul class="widget-content aside_hot_comment"><li class="list clearfix"><a href="https://www.fsgp.cn/p/baike/65536.html" title="Adobe正版软件服务崩溃_AGS弹窗报错或无法验证许可证怎么办【禁用】"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/5e5c3e49e067d55b4723a7a2ef013bbf-120-90-1.jpg" alt="Adobe正版软件服务崩溃_AGS弹窗报错或无法验证许可证怎么办【禁用】" class="img-cover br random-img"></span><div class="new-text"> <p class="title">Adobe正版软件服务崩溃_AGS弹窗报错或无法验证</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-12-16 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/yl/256.html" title="揭秘欧倩怡:才华与美貌并重的艺人风采"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/88a70e273939466b22e9d579e6458c56-120-90-1.jpeg" alt="揭秘欧倩怡:才华与美貌并重的艺人风采" class="img-cover br random-img"></span><div class="new-text"> <p class="title">揭秘欧倩怡:才华与美貌并重的艺人风采</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-20 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/baike/65792.html" title="如何保证html语义化_编写语义化HTML代码规范指南【规范】"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/c310cf8cf4311549dd9e4b6bc500d9ed-120-90-1.png" alt="如何保证html语义化_编写语义化HTML代码规范指南【规范】" class="img-cover br random-img"></span><div class="new-text"> <p class="title">如何保证html语义化_编写语义化HTML代码规范指</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-12-16 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/yl/512.html" title="揭秘孟茜:全方位了解这位才华横溢的女星个人资料"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/b754b7b73665fcb46b2fa901460124a2-120-90-1.png" alt="揭秘孟茜:全方位了解这位才华横溢的女星个人资料" class="img-cover br random-img"></span><div class="new-text"> <p class="title">揭秘孟茜:全方位了解这位才华横溢的女星个人资料</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-21 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/baike/66048.html" title="Win11无法安装打印机0x00000709 Win11替换系统文件修复打印机连接错误"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/71ab34de5ec7bf50806902276fb17511-120-90-1.jpg" alt="Win11无法安装打印机0x00000709 Win11替换系统文件修复打印机连接错误" class="img-cover br random-img"></span><div class="new-text"> <p class="title">Win11无法安装打印机0x00000709 Win</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-12-16 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li><li class="list clearfix"><a href="https://www.fsgp.cn/p/ty/768.html" title="jrs直播无插件直播NBA,畅享篮球赛事-观看指南"><span class="img-wrap br"><img src="https://www.fsgp.cn/zb_users/cache/thumbs/0cc154d4fd581170ba9b64ec634bddb8-120-90-1.png" alt="jrs直播无插件直播NBA,畅享篮球赛事-观看指南" class="img-cover br random-img"></span><div class="new-text"> <p class="title">jrs直播无插件直播NBA,畅享篮球赛事-观看指南</p> <div class="info"> <span class="time"> <i class="iconfont-air icon-time"></i> 2025-10-21 </span> <span class="comment"> <i class="iconfont-air icon-comment"></i> 0 </span> </div> </div></a></li></ul> </section> <section id="divComments" class="widget widget_comments sb br mb"> <p class="c-title mb"><span class="name">最新留言</span></p> <ul class="widget-content divComments"></ul> </section> </div> </aside> </div> <footer class="footer"> <div class="main container"> <div class="f-about fl"> <p class="title pb1">关于本站</p> <div class="intro"></div> <small><span>Copyright © 2025 </span><span class="icp"><a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">川ICP备6666666号</a></span></small> </div> <div class="f-contact fl"> <p class="title pb1">联系我们</p> <div></div> </div> <div class="f-qr fr"> <p class="title pb1">关注我们</p> <div><img class="img br" alt="佛山资讯网二维码" src="https://www.fsgp.cn/zb_users/theme/suiranx_air/image/qr_default.jpg"/></div> </div> <div class="clear"></div> </div> <div id="toolbar" class="toolbar "> <div id="totop" class="btn hidden sb br"> <i class="iconfont-air icon-top"></i> </div> </div> </footer> <script> //移动端点击btn回弹色值 document.getElementById('totop').addEventListener('click', function() { this.style.backgroundColor = '#0084ff'; this.querySelector('.iconfont-air').style.color = 'white'; setTimeout(() => { this.style.backgroundColor = 'white'; this.querySelector('.iconfont-air').style.color = '#333'; }, 500); }); </script> <!--黑色透明遮罩--> <div id="mask-hidden" class="mask-hidden transition"></div> <!--初始化Swiper--> <script> var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', centeredSlides: true, autoplay: 3500, slidesPerView: 1, paginationClickable: true, autoplayDisableOnInteraction: false, spaceBetween: 0, loop: true }); </script> <!--分页--> <!--统计代码--> </body> </html><!--893.17 ms , 46 queries , 1280kb memory , 0 error-->