Javascript Google places.open_现在

Javascript Google places.open_现在,javascript,css,function,google-maps,google-places-api,Javascript,Css,Function,Google Maps,Google Places Api,这里我有一个脚本,它向我展示了GooglePlacesAPI对象的开放时间。 现在我想将.label类上的背景色更改为“红色”,如果place.open\u Now为false,如果为true,则必须保持不变 我怎么能做到 使用此代码,我检查对象的打开时间,但如果place.open\u now为false,如何更改颜色 (function(marker,request,i){ setTimeout(function(){ service.getDetails

这里我有一个脚本,它向我展示了GooglePlacesAPI对象的开放时间。

现在我想将.label类上的背景色更改为“红色”,如果place.open\u Now为false,如果为true,则必须保持不变

我怎么能做到

使用此代码,我检查对象的打开时间,但如果place.open\u now为false,如何更改颜色

(function(marker,request,i){
        setTimeout(function(){
         service.getDetails(request, function(place, status){
          try{
            var time=place.opening_hours.periods[1].open.time;
            var closed=place.opening_hours.periods[1].close.time;
            var closed=[(closed/100).toFixed(0),closed.substr(-2)].join(':');
            marker.set('labelContent',[(time/100).toFixed(0),time.substr(-2)].join(':')+' - '+closed+'</br>'+place.name);
          }
          catch(e){}
         });
        },
        i*250)
      })(marker,request,i);
(功能(标记、请求、i){
setTimeout(函数(){
service.getDetails(请求、功能(位置、状态){
试一试{
var time=place.opening_hours.periods[1].open.time;
var closed=place.opening_hours.periods[1].close.time;
var closed=[(closed/100).toFixed(0),closed.substr(-2)].join(':');
marker.set('labelContent',[(time/100).toFixed(0),time.substr(-2)].join(':')+'-'+closed++'
'+place.name); } 捕获(e){} }); }, i*250) })(标记、请求、i);
如果要检查is place.open\u now true或false,我需要添加
IF
语句,如果
place.open\u now
为false,如何更改背景

*来自google places api文档: 开放时间可能包含以下信息:
open\u now是一个布尔值,指示当前位置是否打开。*

您需要添加此css

.labels.closed {
  background-color: red;
}
这个javascript

var isClosed = true; // find out it's closed or not
marker.set('labelClass', isClosed ? "labels closed" : "labels");

是的,但请更新我的jsbin:我需要把这个css nad js代码放在哪里?对不起,我只使用plnkr.co。您需要完成您的代码,以确定它是否已关闭。我刚刚做了一个示例。谢谢,但我尝试了:var isClosed=place.open\u now;如果isClosed=true;//找出它是否关闭标记。set('labelClass',isClosed?“labels closed”:“labels”);,但效果不好