通过选择`property`属性获取`Meta`属性`content` [英] Get `Meta` attribute `content` by selecting `property` attribute

查看:118
本文介绍了通过选择`property`属性获取`Meta`属性`content`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery中你可以这样做:

In jQuery you can do this:

$("meta[property='fb:app_id']").attr("content");

这将为您提供内容属性值来自 meta -tag,带有属性属性fb:app_id。

Which will give you the content attribute value from the meta-tag with property attribute "fb:app_id".

我怎样才能在普通的'Javascript中做到这一点?

How can I do this in plain ol' Javascript?

提前谢谢你。 : - )

Thank you in advance. :-)

Kenneth

推荐答案

不如JQuery I那么优雅恐怕......

Not as elegant as JQuery I'm afraid...

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

var fbAppIdContent = "";
for (var i = 0; i < metaTags.length; i++) {
    if (metaTags[i].getAttribute("property") == "fb:app_id") {
        fbAppIdContent = metaTags[i].getAttribute("content");
        break;
    }
}

console.log(fbAppIdContent);

这篇关于通过选择`property`属性获取`Meta`属性`content`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆