Bootstrap modal Google Place自动完成未在引导模式中显示
修复更新: 我初始化这个盒子的方式似乎引起了一些问题 这是修复它的方法Bootstrap modal Google Place自动完成未在引导模式中显示,bootstrap-modal,google-maps-api-2,Bootstrap Modal,Google Maps Api 2,修复更新: 我初始化这个盒子的方式似乎引起了一些问题 这是修复它的方法 <script> $(function () { var input = document.getElementById("keyword"); var autocomplete = new google.maps.places.Autocomplete(input); $('#my-modal').modal('show'); }); &l
<script>
$(function () {
var input = document.getElementById("keyword");
var autocomplete = new google.maps.places.Autocomplete(input);
$('#my-modal').modal('show');
});
</script>
<style>
.pac-container {
z-index: 10000 !important;
}
</style>
$(函数(){
var输入=document.getElementById(“关键字”);
var autocomplete=new google.maps.places.autocomplete(输入);
$('my modal').modal('show');
});
.pac集装箱{
z指数:10000!重要;
}
更新:我已经更新了非常简单的代码,之所以这样做是因为它使用的是较旧的引导和jquery,所以我假设因为我使用的是较新的,所以我遇到了问题
我只想在bootstrap(3.3)模型中显示一个自动完成框,并让它在您键入时显示结果
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Test</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"> </script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</head>
<body>
<div>
<div id="my-modal" class="modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<input name="keyword" id="keyword" type="text" />
</div>
</div>
</div>
</div>
<script>
$(function () {
$("#my-modal").modal({
show: false
}).on("shown", function () {
var input = document.getElementById("keyword");
var autocomplete = new google.maps.places.Autocomplete(input);
});
$('#my-modal').modal('show');
});
</script>
</body>
</html>
试验
$(函数(){
$(“#我的模态”).model({
节目:假
}).on(“显示”,函数(){
var输入=document.getElementById(“关键字”);
var autocomplete=new google.maps.places.autocomplete(输入);
});
$('my modal').modal('show');
});
这个问题解决了
<script>
$(function () {
var input = document.getElementById("keyword");
var autocomplete = new google.maps.places.Autocomplete(input);
$('#my-modal').modal('show');
});
</script>
<style>
.pac-container {
z-index: 10000 !important;
}
</style>
$(函数(){
var输入=document.getElementById(“关键字”);
var autocomplete=new google.maps.places.autocomplete(输入);
$('my modal').modal('show');
});
.pac集装箱{
z指数:10000!重要;
}
如果您仍在查看
var pacContainerInitialized = false;
$('#inputField').keypress(function() {
if (!pacContainerInitialized) {
$('.pac-container').css('z-index', '9999');
pacContainerInitialized = true;
}
});
加上
.pac-container {
z-index: 10000 !important;
}
如果与Angular 2+配合使用,请确保使用ng deep
::ng-deep .pac-container
{
z-index: 99999 !important;
}
中未定义
id=“map\u canvas”
JS@Shehary我更新了代码,使其更简单,与画布无关,但仍然不起作用。pac容器{z-index:10000!重要;}这适用于meExplanation:。pac容器
是Google自动完成结果的包装div元素。在这种情况下,modal已经具有较高的z索引。因此,您必须设置比模式更高的z-index