【问题标题】:Combine c# and google maps javascript API结合 c# 和 google maps javascript API
【发布时间】:2014-09-21 08:43:34
【问题描述】:

我希望我的浏览器运行这段代码:

<!DOCTYPE html>
<html>
  <head>
    <title>Asynchronous Loading</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
    <script>
        function initialize() {
            var mapOptions = {
                zoom: 8,
                center: new google.maps.LatLng(-34.397, 150.644)
            };

            var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
        }

        function loadScript() {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' +
      'callback=initialize';
            document.body.appendChild(script);
        }

        window.onload = loadScript;

    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

我想将代码作为带有 aspx 文件的字符串发送:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
 
    string s2 = @"


<script>
 function initialize() {
  var mapOptions = {
    zoom: 8,
    center: new google.maps.LatLng(-34.397, 150.644)
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);
}

function loadScript() {
  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&' +
      'callback=initialize';
  document.body.appendChild(script);
}

window.onload = loadScript;";

</script>


<html>
  <head runat="server">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <title>Info windows</title>
    <style>
      html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
    </style>
   
    <%Response.Write(s2 + "</script>"); %>
  </head>
  <body>
      <form id="form1" runat="server">
    <div id="map-canvas">
    
    </div>

     </form>
  </body>
</html>

当我尝试运行它时,它不显示地图。好像它不读取 javascript。 有人可以告诉我我的代码有什么问题吗?

【问题讨论】:

    标签: javascript html asp.net google-maps


    【解决方案1】:

    也许你是对的,它不读取 JavaScript。所以一个快速的建议:我注意到您没有将type 属性添加到脚本声明中,您可以先尝试添加它,类似于下面的代码吗?

    <script type="text/javascript">
        $('.selectpicker').selectpicker();
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-02
      • 1970-01-01
      • 2015-04-14
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多