更新时间:2022-12-03 12:51:21
这听起来像是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>