2014-10-01 111 views
0

任何想法为什么在一个网站上我无法获得<meta>信息?无法通过jQuery获取元信息

我使用:

$.find("meta[name='description']").attr("content"); 

要获取:

<meta name="description" content="My description"> 

为什么我无法检索这些DATAS?

任何想法?

谢谢。

+0

是否值得指出的是,有*不* [ '.find()'](http://api.jquery.com/jQuery.find),这将解释它不工作?不过你可能会考虑'$('meta [name =“description”]')。attr('content')'。如果您在使用jQuery时遇到问题,请尝试阅读[API](http://api.jquery.com/),它非常好。 – 2014-10-01 19:26:30

+0

尝试$(“head meta [name ='description']”)。attr(“content”);. .find()对jquery对象起作用,而不是jquery本身。 – ray9209 2014-10-01 19:27:28

+0

你什么时候调用jQuery片段? – 2014-10-01 19:27:36

回答

2

通行证jQuery的直接选择和检索content属性的值,像这样:

$('meta[name="description"]').attr("content"); 
+0

这是要做到这一点的方法,除非您特别需要缩小您寻找元标记的范围。你几乎肯定不会。 – 2014-10-01 19:36:19

1

发现它在头标签

$("head").find("meta[name='description']").attr("content");