Google Place Autocomplete 未显示在 Bootstrap 模式中

2024-01-15

修复更新: 看来我初始化盒子的方式引起了问题 这是修复它的方法

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

更新:我已经将代码更新为非常简单,原因是http://jsfiddle.net/g8vxmLn9/1/ http://jsfiddle.net/g8vxmLn9/1/有效是因为它使用较旧的 bo​​otstrap 和 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>

这解决了它

<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Google Place Autocomplete 未显示在 Bootstrap 模式中 的相关文章

随机推荐