gpt4 book ai didi

javascript - Google Place Autocomplete API 下拉列表未显示在模态中

转载 作者:行者123 更新时间:2023-11-30 08:32:15 26 4
gpt4 key购买 nike

我是使用 Bootstrap 的新手。我正在尝试将 Google JS Place Autocomplete API 与 bootstrap 3.0 Modal 集成。

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

我在 stackoverflow 和互联网上尝试了多个 z-index 帮助答案,但它们似乎对我不起作用。

最佳答案

下拉菜单与 #searchModal (1041) 的 z-index 竞争。

使用以下 CSS 定义,下拉菜单应显示在顶部:

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

这是 the fiddle .请将“YOUR_API_KEY”替换为您自己的。

关于javascript - Google Place Autocomplete API 下拉列表未显示在模态中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35875124/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com