如何使用jQuery(schema.org微格式)查找和读取元数据?

时间:2011-11-01 16:14:44

标签: javascript jquery html

我正在构建Google地图应用程序,并且我想从我的HTML中读出schema.org指定的元数据,以绘制我的地图标记。

例如:

<li itemscope="itemscope" itemtype="http://schema.org/LocalBusiness">
...some html... 
  <div class="geo" itemprop="geo" itemscope="itemscope" itemtype="http://schema.org/GeoCoordinates">
    <meta itemprop="latitude" content="43.681505" />
    <meta itemprop="longitude" content="-79.294455" />
  </div>
</li>

有没有一种简单的方法可以查询纬度和经度值,而无需循环遍历所有内容?

2 个答案:

答案 0 :(得分:22)

你试过这个吗?

jQuery(function($){
  var latitude = $('.geo meta[itemprop="latitude"]').attr("content");
  var longitude = $('.geo meta[itemprop="longitude"]').attr("content");
});

答案 1 :(得分:4)

您可以获得如下数据:

$('meta[itemprop="latitude"]').attr('content')