javascript – 将脚本添加到asp.net内容页面
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 将脚本添加到asp.net内容页面,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2297字,纯文字阅读大概需要4分钟。
内容图文
![javascript – 将脚本添加到asp.net内容页面](/upload/InfoBanner/zyjiaocheng/799/0003cdedde53480e924b51ba6ed8e4b8.jpg)
我有一个谷歌地图脚本,但我无法弄清楚如何将其添加到我的asp.net内容页面.将脚本添加到页面的正确方法是什么?
看代码:
<%@ Page Title="Our Location" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="Location.aspx.vb" Inherits="About_Location" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
##map{ height: 100% }
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server" onl oad="codeAddress()">
<script type= "text/javascript">
var geocoder;
var map;
var marker;
function codeAddress() {
alert("hello")
//initializes the map
//create geocoder
geocoder = new google.maps.Geocoder();
//set options for the map being created
var myOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
//create map instance and pass it the myOptions object literal
map = new google.maps.Map(document.getElementById("map"), myOptions);
//geocode to get the lat and lng points of the given address
geocoder.geocode({ 'address': 'New York, New York'}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
//if geocoder finds location
//center the map on the latlng points of the given address
map.setCenter(results[0].geometry.location);
map.setOptions({ zoom: 18 });
//create marker and place it on the address
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: 'New York, New York'
});
}
else {
//if geocoder cannot find location, alert user
alert("Could not find location");
}
});
}
</script>
<div id="map" style="width:700px; height:400px;"></div>
</asp:Content>
解决方法:
将您的脚本放在单独的js文件中,像使用Google地图脚本一样声明它.然后你必须调用它,也许将这个“#map”div id作为参数发送到该脚本,而不是在javascript中硬编码.
在这种情况下,您希望在脚本管理器的页面加载上执行此操作:
ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowGoogleMap", "codeAddress('map');", true);
顺便说一句.对于谷歌地图,您可以使用谷歌地图服务器控制,从服务器端使用管理地图要容易得多:
http://googlemap.codeplex.com/
内容总结
以上是互联网集市为您收集整理的javascript – 将脚本添加到asp.net内容页面全部内容,希望文章能够帮你解决javascript – 将脚本添加到asp.net内容页面所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。