如何使用PHP创建动态页面标题 [英] How to create a dynamic page title using PHP
本文介绍了如何使用PHP创建动态页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以使用H2标签中的文本,并使用它来填充页面标题动态。
我也希望能够使用相同的技术将H2文本添加到元描述中 - 任何人都可以帮助?
解决方案
这听起来像是jQuery会优秀的东西:
< script type ='text / javascript'src ='jquery-1.4-min.js'>< / script>
< script type =text / javascript>
$(document).ready(function(){
document.title = $('h2:first')。text();
});
< / script>
要修改元数据,您将做更多的相同。我强烈推荐 jQuery - 新手对忍者作为一个惊人的方式深入了解jQuery 。
< html>
< head>
< meta description =/>
< script type =text / javascriptsrc =jquery.min.js>< / script>
< script type =text / javascript>
$(document).ready(function(){
$('meta:first')。attr('description',$('h2:first')。text());
alert($('meta:first')。attr('description'));
});
< / script>
< / head>
< body>
< h2>测试123< / h2>
< / body>
< / html>
Hi I was wondering if anyone can help with this PHP problem.
Is it possible to use the text in a H2 tag and use that to populate the page title dynamically.
I'd also like to be able to use this same technique to add the H2 text into the meta description - Can anyone help?
解决方案
That sounds like something that jQuery would excel at:
<script type='text/javascript' src='jquery-1.4-min.js'></script>
<script type="text/javascript">
$(document).ready(function() {
document.title = $('h2:first').text();
});
</script>
To modify the meta data, you would do more of the same. I strongly recommend jQuery - Novice to Ninja as an amazing way to get into great depth with jQuery.
<html>
<head>
<meta description="" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('meta:first').attr('description', $('h2:first').text());
alert($('meta:first').attr('description'));
});
</script>
</head>
<body>
<h2>Testing 123</h2>
</body>
</html>
这篇关于如何使用PHP创建动态页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文