2012-08-10 4 views
0

활성 페이지 제목을 h1 제목 또는 h1 콘텐츠로 어떻게 변경합니까?jQuery 제목을 h1 제목으로 변경하면 활성 페이지로 바뀝니다.

HTML

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

자바 스크립트

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

전체 페이지 제목을 활성화 된 페이지로 변경하고 싶습니다. h1 제목 –

답변

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; 
}); 
+0

후 작성해야 할 내용을 변경하려면 –

+0

document.title = $ (h1); ? –

+0

@BlitzerClarck 무엇을 묻는거야? – iambriansreed

0

ID를 추가 < H1 ID = "myTitle이라는"제목 = "접촉"> 접촉 </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; 
}); 

희망 이게 네가 보이는거야. ng for

+0

원하는 페이지를 변경하고 싶습니다. h1 제목이 없습니다. –

0

는 페이지의 title의 값을 변경하려면

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

미안하지만 임 새로운 나는이 일을 배우려고 노력하고있어? –

0

, 당신은 시도 할 수 있습니다 다음, 현재 페이지의 ID와 제목 속성 일치합니다

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

// or document.title = current; 
+0

감사합니다.이 기능도 작동합니다. –