<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元素。
答案 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;
});