2016-03-20 61 views
8

修复更新: 看来,我被初始化盒子的方式是造成问题 这里是固定的,谷歌地方自动填充在引导模式不显示

<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/工程的原因是因为它使用较旧的引导程序和jQuery,所以我假设,因为我使用较新的我有问题。

我只是想在引导程序(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> 
+0

'ID =“map_canvas”的'是不是在JS – Shehary

+0

定义@Shehary我更新的代码,这样它的简单,没有任何用帆布,仍然不起作用 – Zoinky

回答

23

这个固定

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

这适用于我 –

+0

_Explanation_:'.pac-container'是Google自动完成结果的包装div元素。在这种情况下,模态已经有了很高的'z-index'。所以你必须设置比模态更高的'z-index' – Eranda

3

如果你还在寻找。

    var pacContainerInitialized = false; 
        $('#inputField').keypress(function() { 
          if (!pacContainerInitialized) { 
            $('.pac-container').css('z-index', '9999'); 
            pacContainerInitialized = true; 
          } 
        }); 
+0

谢谢,为我工作! –