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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7969414/
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-24 04:14:10  来源:igfitidea点击:

How to find and read metadata using jQuery (schema.org microformat)?

javascriptjqueryhtml

提问by Diodeus - James MacFarlane

I'm building a Google Maps application and I'd like to read out the metadata, as specified by schema.org, from my HTML to plot my map markers.

我正在构建一个谷歌地图应用程序,我想从我的 HTML 中读出schema.org指定的元数据来绘制我的地图标记。

For example:

例如:

<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>

Is there an easy way to query out the latitude and longitude values without having loop through everything?

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

回答by rmorero

Have you tried this?

你试过这个吗?

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

回答by Alex

You can get at the data like so:

您可以像这样获取数据:

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

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