我正在使用jQuery在隱藏字段中設置一些值,這些值是完全設置的。如何在不點擊提交按鈕的情況下在隱藏字段中獲取值
但問題是隱藏的字段不會顯示值,直到我提交表單。
在提交表單之前是否有值得的值。
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#hdnCountryCode").val(geoip_country_code());
$("#hdnCountyName").val(geoip_country_name());
$("#hdnCity").val(geoip_city());
$("#hdnRegionCode").val(geoip_region());
$("#hdnRegion").val(geoip_region_name());
$("#hdnLatitude").val(geoip_latitude());
$("#hdnLongitude").val(geoip_longitude());
});
</script>
<body>
<form id="form1" runat="server">
<asp:HiddenField runat="server" ID="hdnCountryCode" />
<asp:HiddenField runat="server" ID="hdnCountyName" />
<asp:HiddenField runat="server" ID="hdnCity" />
<asp:HiddenField runat="server" ID="hdnRegionCode" />
<asp:HiddenField runat="server" ID="hdnRegion" />
<asp:HiddenField runat="server" ID="hdnLatitude" />
<asp:HiddenField runat="server" ID="hdnLongitude" />
<asp:Button runat="server" ID="btnV" Text="s" onclick="btnV_Click" />
<%
Google.Values Send = new Google.Values();
Send.CountryName = hdnCountyName.Value;
Send.CountryCode = hdnCountryCode.Value;
Send.RegionName = hdnRegion.Value;
Send.RegionCode = hdnRegionCode.Value;
Send.City = hdnCity.Value;
Send.Latitude = hdnLatitude.Value;
Send.Longitude = hdnLongitude.Value;
%>
</form>
</body>
當傳遞給我的類的屬性時,隱藏字段的值上面的代碼給我「」。但是當我使用按鈕單擊事件相同的代碼返回我,我需要
如果你想檢索代碼的價值,你可以用'$( 「#hdnCountryCode」)VAL()'(沒有傳遞參數'.VAL()',它返回當前值)。你是這個意思嗎?還是你想問如何調試你的代碼? – nnnnnn 2012-01-29 12:02:36
你需要爲此使用AJAX。在填充字段後的'$(document).ready()'中,添加AJAX請求,將這些值發送到服務器,然後您可以在服務器端C#代碼中使用它們。 – 2012-01-29 12:03:10
ShadowWizard可以給我一些解釋,說明你剛剛說的請求 – user1174458 2012-01-29 12:06:32