我正在使用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