gpt4 book ai didi

html - div 为 :target 时更改页面标题

转载 作者:太空宇宙 更新时间:2023-11-04 12:51:49 24 4
gpt4 key购买 nike

我正在开发单页导航系统;有没有办法改变 <title>当 div 为 :target 时的页面(网址中的#divname)?

编辑:是的,抱歉,Jquery/javascript 解决方案也可以。

最佳答案

如果url包含#somePage , 使用 #somePage作为选择器并检索它的 data-title值(value)。

然后设置<title></title>作为该值。 location.hash生产 #somePage

$('a').click(function(event){

event.preventDefault();

if(location.hash) {

var newPageTitle = $(location.hash).data('title');

$('title').text(newPageTitle);

}

});

为您的 div 添加一个数据属性并将其值设置为单击该链接时页面标题的值。

<a href="#somePage">Some Page</a>

<div id="somePage" data-title="This Is The Page Title"></div>

关于html - div 为 :target 时更改页面标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26109721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com