Jquery 选择元[property=og:image]?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8977652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 11:21:10  来源:igfitidea点击:

Jquery Select meta[property=og:image]?

jqueryselectmetafacebook-opengraph

提问by Maxxx

I want to select in Jquery the main photo in a web page, I just have the url page. so I decided to use the meta written for Facebook sharing.

我想在 Jquery 中选择网页中的主照片,我只有 url 页面。所以我决定使用为 Facebook 共享编写的元数据。

I want to select the content of : meta property="og:image" content="http://blablabla.jpg"

我想选择的内容:meta property="og:image" content="http://blablabla.jpg"

I wrote this, but it doesn't work: $("meta[property=og:image]").attr("content");

我写了这个,但它不起作用: $("meta[property=og:image]").attr("content");

Any ideas ? Thank you

有任何想法吗 ?谢谢

回答by AlienWebguy

$('meta[property="og:image"]').attr('content')

$('meta[property="og:image"]').attr('content')

http://jsfiddle.net/ZxmCw/

http://jsfiddle.net/ZxmCw/

回答by Savageman

:imageis parsed as a pseudo-selector. I think you need quotes around "og:image"

:image被解析为伪选择器。我认为你需要在 "og:image" 周围引用