jQuery在activepage中将标题更改为h1标题

jQuery在activepage中将标题更改为h1标题,jquery,html,function,title,page-title,Jquery,Html,Function,Title,Page Title,如何将活动页面标题更改为h1标题或h1内容 HTML 添加id: 接触 希望这就是你想要的试试看 $("ul.pages li").click(function() { $(this).addClass('active').siblings().removeClass('active'); $(".page_content").hide(); var activepage = $('a', this).attr("href"); $(activepage

如何将活动页面标题更改为h1标题或h1内容

HTML

添加id: 接触

希望这就是你想要的

试试看

$("ul.pages li").click(function() {
     $(this).addClass('active').siblings().removeClass('active'); 
     $(".page_content").hide();
     var activepage = $('a', this).attr("href");
     $(activepage).show();
     document.title = $('h1', activepage).first().text();   
     $('title').text( document.title );                        
     return false;
});

使title属性与当前页面的id匹配,然后

$("ul.pages li").click(function() {
     $("ul.pages li").removeClass("active");
     $(this).addClass("active"); 
     $(".page_content").hide();
     var activepage = $(this).find("a").attr("href")
     $(activepage).show();       
     $("h1[title="+activepage+"]").html("The new Title");
     return false;
});

如果要更改页面标题的值,可以尝试:

var current = $('h1').attr('title')
$('title').text(current)

// or document.title = current;

我想改变页面标题,伙计,而不是h1标题,谢谢,为了改变你需要的write@BlitzerClarck你在问什么?这个代码不会改变title@BlitzerClarck更新了它。还使非活动页面
隐藏
删除
。是的,非常感谢dude u r Great抱歉,但我是新手,我正在尝试学习如何不使用此功能?我想将整个页面标题更改为活动页面标题
$("ul.pages li").click(function() {
     $(this).addClass('active').siblings().removeClass('active'); 
     $(".page_content").hide();
     var activepage = $('a', this).attr("href");
     $(activepage).show();
     document.title = $('h1', activepage).first().text();   
     $('title').text( document.title );                        
     return false;
});
$("ul.pages li").click(function() {
     $("ul.pages li").removeClass("active");
     $(this).addClass("active"); 
     $(".page_content").hide();
     var activepage = $(this).find("a").attr("href")
     $(activepage).show();       
     $("h1[title="+activepage+"]").html("The new Title");
     return false;
});
var current = $('h1').attr('title')
$('title').text(current)

// or document.title = current;