使用&lt; span&gt;编辑<title>数据在页面上划分</title>

时间:2013-11-04 08:14:37

标签: jquery title html

<html>
    <head>
        <title></title>
        <script src="js.js"></script>
        <script>
            var name = $("#postheading").text();
            $(document).ready(function(){
                $("title").text(name)    
            }); 
        </script>
    </head>
    <body>
        <span id="postheading">THE PAGE TITLE INFO or POST HEADING</span>
    </body>
</html>

我希望我的问题能从上面的代码中清楚地看出来。但不幸的是它没有用。我有很多页面,并希望从帖子的标题(对于我的博客)获得<title>信息,即我的id="postheading"的span元素。

2 个答案:

答案 0 :(得分:1)

你能试试吗,

    $(document).ready(function(){           
        $("title").text($("#postheading").text());  
    }); 

答案 1 :(得分:0)

首先,您需要检索#postheading块中的document.ready值。其次,您可以使用本机document.title来设置页面标题。试试这个:

$(document).ready(function() {
    var name = $("#postheading").text();
    document.title = name;
});