0

アクティブなページのタイトルをh1タイトルまたはh1コンテンツに変更するにはどうすればよいですか?

HTML

<section id="contact" class="page_content">
            <h2 title="Contact">Contact</h2>  
</section>

JavaScript

$("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();                          
     return false;
});
4

4 に答える 4

2

試す;

$("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;
});
于 2012-08-10T18:39:16.503 に答える
0

IDを追加:<h1 id = "mytitle"title="contact">連絡先</h1>

 $("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();

    // NEW:
    $("#mytitle").text("Hello this is changed");
    $("#mytitle").attr("title","we can also change here");     

    return false;
});

これがあなたが探しているものであることを願っています

于 2012-08-10T18:38:50.473 に答える
0

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;
});
于 2012-08-10T18:41:40.297 に答える
0

ページのの値を変更する場合はtitle、次のことを試すことができます。

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

// or document.title = current;
于 2012-08-10T19:10:52.397 に答える