谷歌地方自动完成API下拉列表不显示在莫代尔

问题描述:

我是新来处理引导。我正在尝试将Google JS Place自动填充API与引导3.0 Modal集成。谷歌地方自动完成API下拉列表不显示在莫代尔

莫代尔CSS:

#searchModal{ 
    z-index:1041 !important; 
} 
.modal-header, h4, .close { 
    background-color: #5cb85c; 
    color: white !important; 
    text-align: center; 
    /*font-size: 30px;*/ 
} 
.modal-footer { 
    background-color: #f9f9f9; 
} 
.modal-backdrop { 
    opacity: 0.5 !important; 
} 

自动完成JS:

function initMap() { 
var oInput = document.getElementById('ocity-input'); 

var oSearchBox = new google.maps.places.SearchBox(oInput); 

oSearchBox.addListener('places_changed', function() { 
    var places = oSearchBox.getPlaces(); 

    places.forEach(function(place) { 
     console.log(place.name); 
     console.log(place.place_id); 
    }); 
}); 
}` 

自动完成CSS:

@CHARSET "ISO-8859-1"; 
html, body { 
    height: 100%;margin: 0;padding: 0; 
} 
.form-control { 
    margin-top: 10px; 
    border: 1px solid transparent; 
    border-radius: 2px 0 0 2px; 
    box-sizing: border-box; 
    -moz-box-sizing: border-box; 
    height: 32px; 
    outline: none; 
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); 
} 
#ocity-input { 
    background-color: #fff; 
    font-family: Roboto; 
    font-size: 15px; 
    font-weight: 300; 
    margin-left: 12px; 
    padding: 0 11px 0 13px; 
    text-overflow: ellipsis; 
    width: 300px; 
} 
#ocity-input:focus { 
    border-color: #4d90fe; 
} 
.ocity-container { 
    font-family: Roboto; 
    z-index: 10000; 
    display: block !important; 
} 

模态代码:

<div class="container"> 
    <div class="modal fade" id="searchModal" role="dialog"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 
       <div class="modal-header" style="padding: 35px 50px;"> 
        <h4 style="text-align: center;"> 
         <span class="logo">Name</span> 
        </h4> 
       </div> 
       <div class="modal-body" style="padding: 40px 50px;"> 
        <form role="form"> 
         <div class="form-group"> 
          <input id="ocity-input" class="form-control" type="text" placeholder="Origin"> 
         </div> 
         <button type="submit" class="btn btn-success btn-block"> 
          <span class="fa fa-undo"></span> Lets Go 
         </button> 
        </form> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

我已经尝试了多个z-index帮助在stackoverflow和互联网上的答案,但他们似乎并没有为我工作。

该下拉与z指数#searchModal(1041)竞争。

用下面的CSS定义下拉应该出现在最前面:

.pac-container { 
    z-index: 1042; 
} 

这里的the fiddle。请用您自己的一个替换“YOUR_API_KEY”。

+0

它确实修复。我没有意识到.pac容器是必不可少的。我将pac-container修改为我的输入字段ID – yashgarg1232