我要提取<p>
html 属性中的内容,<meta content='**I want to extract here**' name='description'/>
。怎样才能完成这项工作。
我正在使用 blogger.com,所以在 blogger.com 中我想提取 <p>
元标记中的内容。请帮我。我尝试了很多,但都失败了。
最佳答案
在文档加载时运行此 JavaScript。
// JavaScript
var p = document.getElementsByTagName("p")[0];
console.log(p.textContent);
var metaTag = document.querySelector('meta[name="description"]');
console.log(metaTag);
metaTag.setAttribute("content",p.textContent);
console.log(metaTag);
<!-- Sample HTML -->
<meta content='**I want to extract here**' name='description'/>
<p>some text</p>
关于javascript - 如何提取html属性中的html <p>内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43566665/