我有问题。 我使用jQuery进行元内容更改,但元内容没有改变。如何使用jQuery更改元内容。 谢谢!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<meta id="meta-element" property='og:title' content="the title"/>
<meta property="og:description" content="the desciption" />
</head>
<body>
<script>
$("meta[property='og:title']").attr("content", 'My title');
</script>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_inline_share_toolbox"></div>
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-599ab21e622f447a"></script>
</body>
</html>
答案 0 :(得分:-2)
您可以通过以下方式使用jQuery:
<script>
$("meta[property='og\\:title']").attr("content", 'My title');
</script>
如果您使用的是chrome(请勿使用属性,请使用名称):
<script>
$("meta[name='og:title']").attr("content", 'My title');
</script>