我怎样才能获得expr:Blogger使用JavaScript的内容价值

时间:2015-12-26 11:49:36

标签: javascript blogger

如何使用JavaScript从Blogger获取expr:content值?

<meta expr:content='data:blog.blogId' itemprop='blogId'/>
<meta expr:content='data:post.id' itemprop='postId'/>

我尝试了getElementsByTagName("meta")

var x = document.getElementsByTagName("meta");

以及querySelectorAll()

var metas = document.querySelectorAll("meta[expr\\:content]");
for (i = 0; i < metas.length; i++) {
console.log(metas[i].getAttribute("expr:content"))}
txt=x.expr:content;

但是我没有收到任何结果,我希望有两个接收结果的变量

x=number of blogId
y=number of postId

3 个答案:

答案 0 :(得分:0)

尝试

var blogId = document.querySelector("meta[itemprop='blogId']").getAttribute('expr:content'),
    postId = document.querySelector("meta[itemprop='postId']").getAttribute('expr:content');
console.log(postId);
console.log(blogId);

Example

答案 1 :(得分:0)

试试这个:

var metas = document.getElementsByTagName("meta"),
    metaData = {}, i, item;
for (i = 0; i < metas.length; i++) {
    item = metas[i].getAttribute("itemprop");
    if (item == "blogId" || item == "postId"){
        metaData[item] = metas[i].getAttribute("expr:content");
    }
}
    console.log(metaData); // this should give you an object with needed data

答案 2 :(得分:0)

将以下脚本放在&lt; b:includable id =&#39; post&#39;之后。 VAR =&#39;后&#39;&GT;

<script>
    var myBlogId = &#39;<data:blog.blogId/>&#39;
    var myPostId = &#39;<data:post.id/>&#39;
</script>