1
我試圖從2 asp:HiddenFields中取值並將它們存儲到JavaScript中的var latitudeDB
,var longitudeDB
中。這兩個值設置爲HiddenFields來自我的數據庫。我已經檢查了Debug.WriteLine
以檢查網站啓動時的2個值,它們都是數據庫中的確切值。獲取HiddenField的值並將其傳入JS中的var
請問我怎樣才能從HiddenFields 2點的值存儲到var latitudeDB
和var longitudeDB
爲未來的用途?而且,這兩個值應該是FLOAT/DOUBLE使用...
在Page_Load中,
foreach (DataRow r in ds.Tables[0].Rows)
{
accountDB = r["AccountStatus"].ToString();
latitudeDB = Convert.ToDouble(r["Latitude"]);
longitudeDB = Convert.ToDouble(r["Longitude"]);
usernameDB = r["Username"].ToString();
ipDB = r["IPAddressOfCreation"].ToString();
}
HF_Latitude.Value = latitudeDB.ToString();
HF_Longitude.Value = longitudeDB.ToString();
Debug.WriteLine(HF_Latitude.Value);
Debug.WriteLine(HF_Longitude.Value);
在我的服務器端表單(JavaScript的),
<script type="text/javascript">
function initMap() {
var latitudeDB = parseFloat(document.getElementById("<%= HF_Latitude.ClientID %>").value);
var longitudeDB = parseFloat(document.getElementById("<%= HF_Longitude.ClientID %>").value);
//var latitudeDB = $("#<%= HF_Latitude.ClientID %>").val();
//var longitudeDB = $("#<%= HF_Longitude.ClientID %>").val();
var mapProp = {
zoom: 15,
center: new google.maps.LatLng(latitudeDB, longitudeDB),
mapTypeId: google.maps.MapTypeId.HYBRID,
};
var map = new google.maps.Map(document.getElementById("generatedMap"), mapProp);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(latitudeDB, longitudeDB),
map: map,
title: "<div style = 'height:50px;width:120px'><b>Consumer's location:</b><br />Latitude: " + latitudeDB + "<br />Longitude: " + longitudeDB,
});
}
</script>
HiddenFields,
<asp:HiddenField runat="server" ID="HF_Latitude" />
<asp:HiddenField runat="server" ID="HF_Longitude" />
請欣賞任何幫助!非常感謝你...
var latitudeDB = parseFloat(document.getElementById(「<%= HF_Latitude.ClientID%>」)。 var longitudeDB = parseFloat(document.getElementById(「<%= HF_Longitude.ClientID%>」)。 這不工作?我在這裏沒有得到什麼錯誤? – JBO
我剛剛解決了問題@JBO。我把我的hiddenfields放在js下面.. – domster
是的,你也可以讓你的js可執行文件只在$(function(){})= $(document).ready(function(){}) – JBO