我如何将JS放入Visual Studio中的自己的文件中?

How would I put the JS into its own file in Visual Studio

本文关键字:自己的 文件 Studio Visual JS 放入      更新时间:2023-09-26

我在Visual Studio 2013的html文件中有一些JS。我只是不知道如何把它放在自己的JS文件VS.我怎么把

<script type="text/javascript"
            src="https://maps.googleapis.com/maps/api/js?key=12345&sensor=false">
    </script>

到自己的。js文件?

然后我该怎么写函数

<script type="text/javascript">
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
            mapOptions);
      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>

放到自己的文件中?我正试图从html文件中删除它们,以便清晰

首先,使用Add > New Item添加一个新文件,并选择一个JavaScript文件(在新项目对话框中可以称为JScript)。

比如叫它map.js

然后添加一个script标签,如下:

<script src="https://maps.googleapis.com/maps/api/js?key=12345&sensor=false"></script>
<script src="map.js"></script>

如果你积累了一些脚本,你可能想使用。net中的捆绑特性——但这只适用于你的小代码段。