javascript - 如何将 vb.net 变量加载到 JavaScript

标签 javascript vb.net

我正在尝试将谷歌地图添加到我的网站,但我希望能够从数据库加载值,而不是修复该位置的纬度和经度。如何从 vb.net 获取变量并将其传递给 javascript?我试过:

<% Response.Write("<script>
    function initialize() {
        var myLatlng = new google.maps.LatLng(1.123456, 1.123456);
        var mapOptions = {
            zoom: 16,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title: 'KH Automotive Location'
        });
    }

    google.maps.event.addDomListener(window, 'load', initialize);

</script>")%>

new google.maps.LatLng(<%=latitude%>, <%=longitude%>);

请帮忙。谢谢

最佳答案

有时,当我需要绝对确定(例如使用翻译/本地化的字符串)内容时,我会将其写到页面上某处的隐藏 DIV(或隐藏的 INPUT)中。

<div style='display:none' id='my_data'>stuffstuffstuff</div>

然后我只读取 DIV(或 INPUT,无论我使用什么)的内容。在其中添加“runat=server”,并能够从代码隐藏中写入它。

关于javascript - 如何将 vb.net 变量加载到 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26248215/

相关文章:

php - 使用 Hash(#) 的 Ajaxpageloak,有数字时异常(exception)(例如 : #1)

mysql - 如何从另一台PC在线连接到MySQL数据库?网络

arrays - 将整数转换为字节数组 VB.net

WebBrowser 中的 Javascript 控制台

javascript - Chrome 和 IE 中 Date() 的不同值

javascript - 如何使用 angular2 更新编辑后的切换

html - 将行添加到 webbrowser 对象中的现有表

c# - 在 Zedgraph 中检测鼠标悬停在线上

javascript - 有哪些好的 JS 调试工具?

javascript - 如何将时刻日期转换为字符串并删除时刻对象