0

使用 Bootstrap 3 导航栏,我想在输入文本字段上显示 Google 位置选项。以下是相同的屏幕截图:

在此处输入图像描述

从屏幕截图可以看出,当navbar固定时,选项显示在后面。并且,当navbar是静态时,选项会按预期显示。我希望在修复导航栏后正确显示选项。

我试图将代码指向 bootply,但它不起作用。JSFiddle的工作代码。另外,代码如下:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Navbar Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">

    <script src="https://maps.googleapis.com/maps/api/js?libraries=places&sensor=false"></script>

  </head>

  <body style="min-height:      2000px;">

    <div class="container">

      <!-- Static navbar -->
      <div class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Find <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li>
                    <form class="navbar-form navbar-left" role="search">
                      <div class="form-group">
                        <input type="text" name="search" style="width: 20em;" class="form-control" placeholder="Search">
                      </div>
                      <button type="submit" class="btn btn-default">Submit</button>
                    </form>
                </li>
              </ul>
            </li>
          </ul>

        </div><!--/.nav-collapse -->
      </div>



    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
  </body>
</html>

<script>

    window.onload = function() {

        var options = {
            types: ['geocode']
        };

        var inputField;     
        inputField = document.getElementsByName( 'search' )[0];
        new google.maps.places.Autocomplete( inputField, options );

    };

</script>

请帮忙。

提前非常感谢!

4

1 回答 1

2

这是因为元素的 z-index。尝试更改 .pac-container 的 z-index。示例:.pac-container { z-index: 9999; }。

于 2013-12-17T13:28:24.307 回答