【问题标题】:Run custom jquery file in bootstrap but failed在引导程序中运行自定义 jquery 文件但失败
【发布时间】:2015-04-07 09:52:12
【问题描述】:

我用 GoogleMap API 编写了一个 jquery 脚本,当我把它放在空白的 HTML 页面中时就可以工作了,比如:

<!DOCTYPE html>
<html>
<head>
<script>
  //my script here...
</scripn>
</head>
<body>
<section id="about" class="container content-section text-center">
    <div class="row">
        <div class="col-lg-8 col-lg-offset-2">
            <div id="map-canvas"></div>  
        </div>
    </div>
</section>
//it works fine.
</body>
</html>

现在我正在尝试将 jquery 脚本打包到一个 js 文件中,并将其包含到引导程序中,但工作失败了。 我曾在这里寻找一些解决方案,但都没有为我工作。
1.Custom jQuery Functions
2.Bootstrap Custom jQuery
3.Run js script anyway at initialization
4.Bootstrap modal opening on page load
我正在使用这个引导程序template。请帮助我,谢谢。

JS文件被包含在&lt;footer&gt;标签中

<!-- jQuery -->
<script src="js/jquery.js"></script>    
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="js/jquery.easing.min.js"></script>
<!-- Google Maps API Key - Use your own API key to enable the map feature. More information on the Google Maps API can be found at https://developers.google.com/maps/ -->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCRngKslUGJTlibkQ3FkfTxj3Xss1UlZDA&sensor=false"></script>
<!-- Custom Theme JavaScript -->
<script src="js/grayscale.js"></script>
<!-- drink Map JavaScript -->
<script src="js/drinkmap.js"></script>

jquery 脚本是这样包装的

$(function() {
  var x = [];
  var list = [];
  var map;
  for(var s = 0; s < jsfile.length; s++) {
    $.getJSON(jsfile[s], function(json) {
      for(var i = 0; i < json.length; i++) {
        x.push({
        //push some info like name, latlng
        });
      }
    });  
  }
  //start navigator
  function getUserGeolocation() {
    if(navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(parsePosition, noGeolocation);
    } else { handleNoGeolocation(false); }
  }
  //success callback of getCurrentPosition and do map work
  function parsePosition(pos) { ... }
  //error callback of geolocation.getCurrentPosition
  function noGeolocation() { handleNoGeolocation(true); }
  function handleNoGeolocation(errorFlag) { ... }
});

我在 firefox 调试中遇到这样的错误

SyntaxError: illegal character
}

或者我无法在&lt;div&gt; 中显示地图。

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap google-maps


    【解决方案1】:

    对于像我一样也在寻找类似问题的答案的人, 最后我发现这是一种 Vagrant/VirtualBox Nginx 缓存行为问题...... 问题和解决方案在这里供参考:https://github.com/mitchellh/vagrant/issues/351

    我进入位于/etc/nginx/nginx.conf 并将sendfile on; 更改为sendfile off;,然后重新启动nginx,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 2019-11-07
      相关资源
      最近更新 更多