在引导程序中运行自定义jquery文件,但失败

Run custom jquery file in bootstrap but failed

本文关键字:文件 失败 jquery 自定义 引导程序 运行      更新时间:2023-09-26

我用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.自定义jQuery函数
2.引导程序自定义jQuery
3.初始化时仍然运行js脚本
4.页面加载时启动模式打开
我使用的是这个引导模板。请帮我做这件事,谢谢。

JS文件包含在<footer>标签中

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

或者我不能在CCD_ 2中显示地图。

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

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